From a7454d8a6325566753358b37ffabfae2faa0ca7f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 28 四月 2021 19:46:49 +0800
Subject: [PATCH] 拼多多授权调整,支持小程序跳转

---
 fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java |  785 +++++++++++++++++++++++++++----------------------------
 1 files changed, 389 insertions(+), 396 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java b/fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java
index 4e07733..54c3f39 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java
@@ -1,396 +1,389 @@
-package com.yeshi.fanli.controller;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.Date;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import com.yeshi.fanli.entity.bus.user.UserActiveLog;
-import com.yeshi.fanli.entity.bus.user.UserInfo;
-import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
-import com.yeshi.fanli.entity.taobao.TaoBaoUnionAuthRecord;
-import com.yeshi.fanli.exception.taobao.TaoBaoAuthException;
-import com.yeshi.fanli.exception.user.UserExtraTaoBaoInfoException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.user.UserActiveLogService;
-import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
-import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
-import com.yeshi.fanli.service.inter.user.tb.TaoBaoUnionAuthRecordService;
-import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
-import com.yeshi.fanli.util.AESUtil;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.RedisKeyEnum;
-import com.yeshi.fanli.util.RedisManager;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.TaoBaoConstant;
-import com.yeshi.fanli.util.ThreadUtil;
-import com.yeshi.fanli.util.VersionUtil;
-import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
-
-import net.sf.json.JSONObject;
-
-/**
- * 鎺堟潈鍥炶皟
- * 
- * @author Administrator
- *
- */
-@Controller
-@RequestMapping("client/v1/auth/callback")
-public class AuthCallBackController {
-
-	@Resource
-	private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
-
-	@Resource
-	private TaoBaoUnionAuthRecordService taoBaoUnionAuthRecordService;
-
-	@Resource
-	private UserAccountMsgNotificationService userAccountMsgNotificationService;
-
-	@Resource
-	private UserInfoModifyRecordService userInfoModifyRecordService;
-
-	@Resource
-	private RedisManager redisManager;
-
-	@Resource
-	private UserActiveLogService userActiveLogService;
-
-	@RequestMapping(value = "tb")
-	public void tb(String code, String state, HttpServletRequest request, HttpServletResponse response) {
-		LogHelper.test("娣樺疂鎺堟潈鍥炶皟:" + code + "锛�" + state);
-		if (StringUtil.isNullOrEmpty(code) || StringUtil.isNullOrEmpty(state)) {
-			LogHelper.error("娣樺疂鎺堟潈鍥炶皟鍑洪敊");
-			try {
-				response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/fail.html?code=1");
-			} catch (IOException e1) {
-				e1.printStackTrace();
-			}
-			return;
-		}
-
-		try {
-			String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCode, code);
-			if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key)))
-				return;
-			redisManager.cacheCommonString(key, 1 + "", 5);
-		} catch (Exception e) {
-
-		}
-
-		String stateStr = null;
-		Long time = null;
-		Long uid = null;
-		String source = null;
-		try {
-			stateStr = AESUtil.decrypt(state, Constant.UIDAESKEY);
-			JSONObject json = JSONObject.fromObject(stateStr);
-			time = json.optLong("t");
-			uid = json.optLong("u");
-			source = json.optString("s");
-		} catch (Exception e) {
-			try {
-				state = URLDecoder.decode(state, "UTF-8");
-			} catch (UnsupportedEncodingException e1) {
-				e1.printStackTrace();
-			}
-			stateStr = AESUtil.decrypt(state, Constant.UIDAESKEY);
-			JSONObject json = JSONObject.fromObject(stateStr);
-			time = json.optLong("t");
-			uid = json.optLong("u");
-			source = json.optString("s");
-		}
-
-		LogHelper.userErrorInfo("娣樺疂鎺堟潈鍥炶皟state:" + state);
-
-		LogHelper.userErrorInfo("娣樺疂鎺堟潈鍥炶皟瑙e瘑:" + stateStr);
-
-		int errCode = 0;
-		if (StringUtil.isNullOrEmpty(stateStr)) {
-			// 瑙e瘑閿欒
-			errCode = 1;
-		}
-
-		if (System.currentTimeMillis() - time > 1000 * 60 * 10L) {
-			// 杩囨椂
-			errCode = 2;
-		}
-		if (uid == null || uid.longValue() == 0L)
-			errCode = 3;
-
-		// 璁″叆璁板綍
-
-		try {
-			String result = TaoKeApiUtil.getAccessToken(code, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
-					TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
-			JSONObject data = JSONObject.fromObject(result);
-			data = data.optJSONObject("top_auth_token_create_response").optJSONObject("token_result");
-			String accessToken = data.optString("access_token");
-			String openUid = data.optString("taobao_open_uid");
-			String taoBaoUid = data.optString("taobao_user_id");
-			String nickName = data.optString("taobao_user_nick");
-			try {
-				nickName = URLDecoder.decode(nickName, "UTF-8");
-			} catch (Exception e) {
-			}
-			final String name = nickName;
-			LogHelper.test("uid:" + uid + "\n accessToken:" + accessToken);
-
-			// 鑾峰彇娓犻亾ID涓庝細鍛業D
-			if ("share".equalsIgnoreCase(source)) {
-				String relationId = null;
-
-				try {
-					relationId = TaoKeApiUtil.getRelationId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
-							TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 娓犻亾ID
-				} catch (TaoBaoAuthException e) {
-					if (e.getCode() == TaoBaoAuthException.CODE_NOT_REAL_NAME)
-						userAccountMsgNotificationService.taoBaoAuthFail(uid, name, "娣樺疂璐﹀彿鏈疄鍚�");
-				}
-
-				if (StringUtil.isNullOrEmpty(relationId))
-					LogHelper.test(uid + "娓犻亾澶囨澶辫触");
-				try {
-					userExtraTaoBaoInfoService.addRelationId(uid, relationId, taoBaoUid, nickName, true);
-				} catch (UserExtraTaoBaoInfoException e) {
-					LogHelper.test(e.getMsg());
-					errCode = 5;
-				}
-
-				final String relationId2 = relationId;
-				// 寮傛鐢宠浼氬憳ID
-				final Long fuid=uid;
-				ThreadUtil.run(new Runnable() {
-
-					@Override
-					public void run() {
-						String specialId = null;
-						try {
-							specialId = TaoKeApiUtil.getSpecialId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
-									TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
-						} catch (TaoBaoAuthException e1) {
-
-						}
-
-						if (StringUtil.isNullOrEmpty(specialId))
-							LogHelper.test(fuid + "浼氬憳澶囨澶辫触");
-						try {
-							userExtraTaoBaoInfoService.addSpecialId(fuid, specialId, taoBaoUid, name, true);
-
-							if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId2))
-								userInfoModifyRecordService.addModifyRecord(fuid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
-						} catch (UserExtraTaoBaoInfoException e) {
-							LogHelper.test(e.getMsg());
-						}
-					}
-				});
-
-				// 绋嶄綔寤惰繜
-				Thread.sleep(50);
-			} else if ("zigou".equalsIgnoreCase(source)) {
-				String specialId = null;
-
-				try {
-					specialId = TaoKeApiUtil.getSpecialId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
-							TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
-				} catch (TaoBaoAuthException e) {
-					if (e.getCode() == TaoBaoAuthException.CODE_NOT_REAL_NAME)
-						userAccountMsgNotificationService.taoBaoAuthFail(uid, name, "娣樺疂璐﹀彿鏈疄鍚�");
-				}
-
-				if (StringUtil.isNullOrEmpty(specialId))
-					LogHelper.test(uid + "浼氬憳澶囨澶辫触");
-				try {
-					userExtraTaoBaoInfoService.addSpecialId(uid, specialId, taoBaoUid, nickName, true);
-				} catch (UserExtraTaoBaoInfoException e) {
-					LogHelper.test(e.getMsg());
-					errCode = 5;
-				}
-				final Long fuid=uid;
-
-				final String specialId2 = specialId;
-				// 寮傛鐢宠娓犻亾ID
-				ThreadUtil.run(new Runnable() {
-
-					@Override
-					public void run() {
-						String relationId = null;
-						try {
-							relationId = TaoKeApiUtil.getRelationId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
-									TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
-						} catch (TaoBaoAuthException e1) {
-						} // 娓犻亾ID
-						if (StringUtil.isNullOrEmpty(relationId))
-							LogHelper.test(fuid + "娓犻亾澶囨澶辫触");
-						try {
-							userExtraTaoBaoInfoService.addRelationId(fuid, relationId, taoBaoUid, name, true);
-
-							if (!StringUtil.isNullOrEmpty(specialId2) && !StringUtil.isNullOrEmpty(relationId))
-								userInfoModifyRecordService.addModifyRecord(fuid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
-						} catch (UserExtraTaoBaoInfoException e) {
-							LogHelper.test(e.getMsg());
-						}
-					}
-				});
-				// 绋嶄綔寤惰繜
-				Thread.sleep(50);
-
-			} else if ("bind".equalsIgnoreCase(source)) {
-
-				boolean bindInfo = true;
-				// 缁戝畾娣樺疂锛歏1.5.3
-				String relationId = null;
-
-				int tbErrorCode = 0;
-				try {
-					relationId = TaoKeApiUtil.getRelationId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
-							TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 娓犻亾ID
-				} catch (TaoBaoAuthException e) {
-					tbErrorCode = e.getCode();
-				}
-
-				if (StringUtil.isNullOrEmpty(relationId)) {
-					LogHelper.test(uid + "娓犻亾澶囨澶辫触");
-					bindInfo = false;
-				}
-
-				String specialId = null;
-				if (bindInfo) {
-					try {
-						specialId = TaoKeApiUtil.getSpecialId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
-								TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
-					} catch (TaoBaoAuthException e) {
-						tbErrorCode = e.getCode();
-					}
-					if (StringUtil.isNullOrEmpty(specialId)) {
-						LogHelper.test(uid + "浼氬憳澶囨澶辫触");
-						bindInfo = false;
-					}
-				}
-
-				if (!bindInfo) {
-					if (tbErrorCode == TaoBaoAuthException.CODE_NOT_REAL_NAME) {
-						userAccountMsgNotificationService.taoBaoAuthFail(uid, name, "娣樺疂璐﹀彿鏈疄鍚�");
-					}
-					errCode = 5;// 淇℃伅鑾峰彇涓嶅叏
-				} else {
-					try {
-						userExtraTaoBaoInfoService.saveUserTaoBaoInfo(uid, relationId, specialId, taoBaoUid, nickName,
-								true);
-
-						if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId))
-							userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
-					} catch (UserExtraTaoBaoInfoException e) {
-						LogHelper.test(e.getMsg());
-						errCode = 6;
-					}
-				}
-
-			}
-
-			if (!StringUtil.isNullOrEmpty(nickName))
-				try {
-					nickName = URLDecoder.decode(nickName, "UTF-8");
-				} catch (UnsupportedEncodingException e) {
-					e.printStackTrace();
-				}
-			TaoBaoUnionAuthRecord record = new TaoBaoUnionAuthRecord();
-			record.setUser(new UserInfo(uid));
-			record.setTaoBaoOpenUid(openUid);
-			record.setTaoBaoUserId(taoBaoUid);
-			record.setTaoBaoUserNick(nickName);
-			record.setCreateTime(new Date());
-			taoBaoUnionAuthRecordService.addAuthRecord(record);
-
-		} catch (Exception e) {
-			errCode = 4;
-			LogHelper.errorDetailInfo(e);
-		}
-
-		UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(uid);
-
-		boolean isNewJump = false;
-		if (activeLog != null) {
-			String platform = null;
-			String version = activeLog.getVersionCode();
-			if (activeLog.getChannel().equalsIgnoreCase("appstore")) {
-				platform = "ios";
-			} else {
-				platform = "android";
-			}
-			if (VersionUtil.greaterThan_2_0(platform, version)) {
-				isNewJump = true;
-			}
-		}
-
-		try {
-			if (errCode == 0)// 鎴愬姛
-			{
-				if ("share".equalsIgnoreCase(source)) {
-					if (isNewJump)
-						response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/success.html");
-					else
-						closeWebPage(response.getWriter());
-				} else if ("zigou".equalsIgnoreCase(source)) {
-					if (isNewJump)
-						response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/success.html");
-					else
-						closeWebPage(response.getWriter());
-				} else if ("bind".equalsIgnoreCase(source)) {
-					if (isNewJump)
-						response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/success.html");
-					else {
-						String script = String.format(
-								"<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.toast(\"鎭枩浣狅紝娣樺疂缁戝畾鎴愬姛\");yestv.finishPage();}</script>",
-								StringUtil.getBase64String("鎭枩浣狅紝娣樺疂缁戝畾鎴愬姛"));
-						response.getWriter().print(script);
-					}
-				}
-			} else {// 澶辫触
-				if ("share".equalsIgnoreCase(source)) {
-					if (isNewJump)
-						response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/fail.html");
-					else
-						closeWebPage(response.getWriter());
-				} else if ("zigou".equalsIgnoreCase(source)) {
-					if (isNewJump)
-						response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/fail.html");
-					else
-						closeWebPage(response.getWriter());
-				} else if ("bind".equalsIgnoreCase(source)) {
-					if (isNewJump)
-						response.sendRedirect("http://apph5.yeshitv.com/flqWeb/h5/tbauth/fail.html");
-					else {
-						String script = String.format(
-								"<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.toast(\"鎶辨瓑锛屾窐瀹濈粦瀹氬け璐");yestv.finishPage();}</script>",
-								StringUtil.getBase64String("鎶辨瓑锛屾窐瀹濈粦瀹氬け璐�"));
-						response.getWriter().print(script);
-					}
-				}
-			}
-		} catch (Exception e) {
-
-		}
-
-	}
-
-	private void closeWebPage(PrintWriter out) {
-		String script = "<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.finishPage();}</script>";
-		out.print(script);
-	}
-
-	@RequestMapping(value = "pinduoduo")
-	public void pinDuoDuo(HttpServletResponse response) {
-
-	}
-
-}
+package com.yeshi.fanli.controller;
+
+import com.yeshi.fanli.entity.bus.user.UserActiveLog;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
+import com.yeshi.fanli.entity.taobao.TaoBaoUnionAuthRecord;
+import com.yeshi.fanli.exception.taobao.TaoBaoAuthException;
+import com.yeshi.fanli.exception.user.UserExtraTaoBaoInfoException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.log.LogManager;
+import com.yeshi.fanli.log.LogType;
+import com.yeshi.fanli.service.inter.user.UserActiveLogService;
+import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
+import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
+import com.yeshi.fanli.service.inter.user.tb.TaoBaoUnionAuthRecordService;
+import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
+import com.yeshi.fanli.util.*;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
+import net.sf.json.JSONObject;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Date;
+
+/**
+ * 鎺堟潈鍥炶皟
+ * 
+ * @author Administrator
+ *
+ */
+@Controller
+@RequestMapping("client/v1/auth/callback")
+public class AuthCallBackController {
+
+	@Resource
+	private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
+
+	@Resource
+	private TaoBaoUnionAuthRecordService taoBaoUnionAuthRecordService;
+
+	@Resource
+	private UserAccountMsgNotificationService userAccountMsgNotificationService;
+
+	@Resource
+	private UserInfoModifyRecordService userInfoModifyRecordService;
+
+	@Resource
+	private RedisManager redisManager;
+
+	@Resource
+	private UserActiveLogService userActiveLogService;
+
+	@RequestMapping(value = "tb")
+	public void tb(String code, String state, HttpServletRequest request, HttpServletResponse response) {
+		LogManager.getLogger(LogType.taobaoAuth).info("娣樺疂鎺堟潈鍥炶皟:" + code + "锛�" + state);
+		if (StringUtil.isNullOrEmpty(code) || StringUtil.isNullOrEmpty(state)) {
+			LogHelper.error("娣樺疂鎺堟潈鍥炶皟鍑洪敊");
+			try {
+				response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/fail.html?code=1");
+			} catch (IOException e1) {
+				e1.printStackTrace();
+			}
+			return;
+		}
+
+		try {
+			String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCode, code);
+			if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key)))
+				return;
+			redisManager.cacheCommonString(key, 1 + "", 5);
+		} catch (Exception e) {
+
+		}
+
+		String stateStr = null;
+		Long time = null;
+		Long uid = null;
+		String source = null;
+		try {
+			stateStr = AESUtil.decrypt(state, Constant.UIDAESKEY);
+			JSONObject json = JSONObject.fromObject(stateStr);
+			time = json.optLong("t");
+			uid = json.optLong("u");
+			source = json.optString("s");
+		} catch (Exception e) {
+			try {
+				state = URLDecoder.decode(state, "UTF-8");
+			} catch (UnsupportedEncodingException e1) {
+				e1.printStackTrace();
+			}
+			stateStr = AESUtil.decrypt(state, Constant.UIDAESKEY);
+			JSONObject json = JSONObject.fromObject(stateStr);
+			time = json.optLong("t");
+			uid = json.optLong("u");
+			source = json.optString("s");
+		}
+
+		LogManager.getLogger(LogType.taobaoAuth).info("娣樺疂鎺堟潈鍥炶皟state:" + state);
+
+		LogManager.getLogger(LogType.taobaoAuth).info("娣樺疂鎺堟潈鍥炶皟瑙e瘑:" + stateStr);
+
+		int errCode = 0;
+		if (StringUtil.isNullOrEmpty(stateStr)) {
+			// 瑙e瘑閿欒
+			errCode = 1;
+		}
+
+		if (System.currentTimeMillis() - time > 1000 * 60 * 10L) {
+			// 杩囨椂
+			errCode = 2;
+		}
+		if (uid == null || uid.longValue() == 0L)
+			errCode = 3;
+
+		// 璁″叆璁板綍
+
+		try {
+			//
+			String result = TaoKeApiUtil.getAccessToken(code, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
+					TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+			JSONObject data = JSONObject.fromObject(result);
+			data = data.optJSONObject("top_auth_token_create_response").optJSONObject("token_result");
+			String accessToken = data.optString("access_token");
+			String openUid = data.optString("taobao_open_uid");
+			String taoBaoUid = data.optString("taobao_user_id");
+			String nickName = data.optString("taobao_user_nick");
+			try {
+				nickName = URLDecoder.decode(nickName, "UTF-8");
+			} catch (Exception e) {
+			}
+			final String name = nickName;
+			LogManager.getLogger(LogType.taobaoAuth).info("uid:" + uid + "\n accessToken:" + accessToken);
+
+			//鎵ц缁戝畾
+            source="bind";
+			// 鑾峰彇娓犻亾ID涓庝細鍛業D
+			if ("share".equalsIgnoreCase(source)) {
+				String relationId = null;
+
+				try {
+					relationId = TaoKeApiUtil.getRelationId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
+							TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 娓犻亾ID
+				} catch (TaoBaoAuthException e) {
+					LogManager.getLogger(LogType.taobaoAuth).error(uid + "娓犻亾澶囨澶辫触:" + e.getMessage());
+					if (e.getCode() == TaoBaoAuthException.CODE_NOT_REAL_NAME)
+						userAccountMsgNotificationService.taoBaoAuthFail(uid, name, "娣樺疂璐﹀彿鏈疄鍚�");
+				}
+
+				try {
+					userExtraTaoBaoInfoService.addRelationId(uid, relationId, taoBaoUid, nickName, true);
+				} catch (UserExtraTaoBaoInfoException e) {
+					LogHelper.test(e.getMsg());
+					errCode = 5;
+				}
+
+				final String relationId2 = relationId;
+				// 寮傛鐢宠浼氬憳ID
+				final Long fuid = uid;
+//				ThreadUtil.run(new Runnable() {
+//
+//					@Override
+//					public void run() {
+//						String specialId = null;
+//						try {
+//							specialId = TaoKeApiUtil.getSpecialId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
+//									TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+//						} catch (TaoBaoAuthException e1) {
+//							LogManager.getLogger(LogType.taobaoAuth).error(fuid + "浼氬憳澶囨澶辫触:" + e1.getMessage());
+//						}
+//
+//						try {
+//							userExtraTaoBaoInfoService.addSpecialId(fuid, specialId, taoBaoUid, name, true);
+//
+//							if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId2))
+//								userInfoModifyRecordService.addModifyRecord(fuid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
+//						} catch (UserExtraTaoBaoInfoException e) {
+//							LogHelper.test(e.getMsg());
+//						}
+//					}
+//				});
+
+				// 绋嶄綔寤惰繜
+				Thread.sleep(50);
+			} else if ("zigou".equalsIgnoreCase(source)) {
+				String specialId = null;
+
+				try {
+					specialId = TaoKeApiUtil.getSpecialId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
+							TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+				} catch (TaoBaoAuthException e) {
+					if (e.getCode() == TaoBaoAuthException.CODE_NOT_REAL_NAME)
+						userAccountMsgNotificationService.taoBaoAuthFail(uid, name, "娣樺疂璐﹀彿鏈疄鍚�");
+					LogManager.getLogger(LogType.taobaoAuth).error(uid + "浼氬憳澶囨澶辫触:" + e.getMessage());
+
+					LogHelper.test("娣樺疂鎺堟潈:"+uid + "浼氬憳澶囨澶辫触:" + e.getMessage());
+				}
+
+				LogHelper.test("娣樺疂鎺堟潈:"+specialId);
+
+				try {
+					userExtraTaoBaoInfoService.addSpecialId(uid, specialId, taoBaoUid, nickName, true);
+				} catch (UserExtraTaoBaoInfoException e) {
+					LogHelper.test(e.getMsg());
+					errCode = 5;
+				}
+				final Long fuid = uid;
+
+				final String specialId2 = specialId;
+				// 寮傛鐢宠娓犻亾ID
+//				ThreadUtil.run(new Runnable() {
+//
+//					@Override
+//					public void run() {
+//						String relationId = null;
+//						try {
+//							relationId = TaoKeApiUtil.getRelationId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
+//									TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+//						} catch (TaoBaoAuthException e1) {
+//							LogManager.getLogger(LogType.taobaoAuth).error(fuid + "娓犻亾澶囨澶辫触:" + e1.getMessage());
+//						}
+//						try {
+//							userExtraTaoBaoInfoService.addRelationId(fuid, relationId, taoBaoUid, name, true);
+//
+//							if (!StringUtil.isNullOrEmpty(specialId2) && !StringUtil.isNullOrEmpty(relationId))
+//								userInfoModifyRecordService.addModifyRecord(fuid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
+//						} catch (UserExtraTaoBaoInfoException e) {
+//							LogHelper.test(e.getMsg());
+//						}
+//					}
+//				});
+				// 绋嶄綔寤惰繜
+				Thread.sleep(50);
+
+			} else if ("bind".equalsIgnoreCase(source)) {
+
+				boolean bindInfo = true;
+				// 缁戝畾娣樺疂锛歏1.5.3
+				String relationId = null;
+
+				int tbErrorCode = 0;
+				try {
+					relationId = TaoKeApiUtil.getRelationId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
+							TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 娓犻亾ID
+				} catch (TaoBaoAuthException e) {
+					LogManager.getLogger(LogType.taobaoAuth).error(uid + "娓犻亾澶囨澶辫触");
+					tbErrorCode = e.getCode();
+				}
+
+				if (StringUtil.isNullOrEmpty(relationId)) {
+					bindInfo = false;
+				}
+
+				String specialId = null;
+				if (bindInfo) {
+					try {
+						specialId = TaoKeApiUtil.getSpecialId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
+								TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+					} catch (TaoBaoAuthException e) {
+						tbErrorCode = e.getCode();
+						LogManager.getLogger(LogType.taobaoAuth).error(uid + "浼氬憳澶囨澶辫触");
+					}
+					if (StringUtil.isNullOrEmpty(specialId)) {
+						bindInfo = false;
+					}
+				}
+
+				if (!bindInfo) {
+					if (tbErrorCode == TaoBaoAuthException.CODE_NOT_REAL_NAME) {
+						userAccountMsgNotificationService.taoBaoAuthFail(uid, name, "娣樺疂璐﹀彿鏈疄鍚�");
+					}
+					errCode = 5;// 淇℃伅鑾峰彇涓嶅叏
+				} else {
+					try {
+						userExtraTaoBaoInfoService.saveUserTaoBaoInfo(uid, relationId, specialId, taoBaoUid, nickName,
+								true);
+
+						if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId))
+							userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
+					} catch (UserExtraTaoBaoInfoException e) {
+						LogHelper.test(e.getMsg());
+						errCode = 6;
+					}
+				}
+
+			}
+
+			if (!StringUtil.isNullOrEmpty(nickName))
+				try {
+					nickName = URLDecoder.decode(nickName, "UTF-8");
+				} catch (UnsupportedEncodingException e) {
+					e.printStackTrace();
+				}
+			TaoBaoUnionAuthRecord record = new TaoBaoUnionAuthRecord();
+			record.setUser(new UserInfo(uid));
+			record.setTaoBaoOpenUid(openUid);
+			record.setTaoBaoUserId(taoBaoUid);
+			record.setTaoBaoUserNick(nickName);
+			record.setCreateTime(new Date());
+			taoBaoUnionAuthRecordService.addAuthRecord(record);
+
+		} catch (Exception e) {
+			errCode = 4;
+			LogHelper.errorDetailInfo(e);
+		}
+
+		UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(uid);
+
+		boolean isNewJump = false;
+		if (activeLog != null) {
+			String platform = null;
+			String version = activeLog.getVersionCode();
+			if (activeLog.getChannel().equalsIgnoreCase("appstore")) {
+				platform = "ios";
+			} else {
+				platform = "android";
+			}
+			if (VersionUtil.greaterThan_2_0(platform, version)) {
+				isNewJump = true;
+			}
+		}
+
+		try {
+			if (errCode == 0)// 鎴愬姛
+			{
+				if ("share".equalsIgnoreCase(source)) {
+					if (isNewJump)
+						response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/success.html");
+					else
+						closeWebPage(response.getWriter());
+				} else if ("zigou".equalsIgnoreCase(source)) {
+					if (isNewJump)
+						response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/success.html");
+					else
+						closeWebPage(response.getWriter());
+				} else if ("bind".equalsIgnoreCase(source)) {
+					if (isNewJump)
+						response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/success.html");
+					else {
+						String script = String.format(
+								"<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.toast(\"鎭枩浣狅紝娣樺疂缁戝畾鎴愬姛\");yestv.finishPage();}</script>",
+								StringUtil.getBase64String("鎭枩浣狅紝娣樺疂缁戝畾鎴愬姛"));
+						response.getWriter().print(script);
+					}
+				}
+			} else {// 澶辫触
+				if ("share".equalsIgnoreCase(source)) {
+					if (isNewJump)
+						response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/fail.html");
+					else
+						closeWebPage(response.getWriter());
+				} else if ("zigou".equalsIgnoreCase(source)) {
+					if (isNewJump)
+						response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/fail.html");
+					else
+						closeWebPage(response.getWriter());
+				} else if ("bind".equalsIgnoreCase(source)) {
+					if (isNewJump)
+						response.sendRedirect("http://apph5.banliapp.com/flqWeb/h5/tbauth/fail.html");
+					else {
+						String script = String.format(
+								"<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href = 'yestv://toast#%s';setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.toast(\"鎶辨瓑锛屾窐瀹濈粦瀹氬け璐");yestv.finishPage();}</script>",
+								StringUtil.getBase64String("鎶辨瓑锛屾窐瀹濈粦瀹氬け璐�"));
+						response.getWriter().print(script);
+					}
+				}
+			}
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+	}
+
+	private void closeWebPage(PrintWriter out) {
+		String script = "<script>if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {setTimeout(function(){window.location.href = 'yestv://finishPage';},100);} else {yestv.finishPage();}</script>";
+		out.print(script);
+	}
+
+	@RequestMapping(value = "pinduoduo")
+	public void pinDuoDuo(HttpServletResponse response) {
+
+	}
+
+}

--
Gitblit v1.8.0