admin
2019-09-09 0922bfdb56bc30125d6fc8e13c50cdda7cd9dc72
fanli/src/main/java/com/yeshi/fanli/controller/AuthCallBackController.java
@@ -14,11 +14,15 @@
import org.springframework.web.bind.annotation.RequestMapping;
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.msg.UserAccountMsgNotificationService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionAuthRecordService;
import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
import com.yeshi.fanli.util.AESUtil;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
@@ -44,6 +48,12 @@
   @Resource
   private TaoBaoUnionAuthRecordService taoBaoUnionAuthRecordService;
   @Resource
   private UserAccountMsgNotificationService userAccountMsgNotificationService;
   @Resource
   private UserInfoModifyRecordService userInfoModifyRecordService;
   @Resource
   private RedisManager redisManager;
@@ -102,12 +112,20 @@
         } catch (Exception e) {
         }
         final String name = nickName;
         // LogHelper.test("uid:" + uid + "\n accessToken:" + accessToken);
         LogHelper.test("uid:" + uid + "\n accessToken:" + accessToken);
         // 获取渠道ID与会员ID
         if ("share".equalsIgnoreCase(source)) {
            String relationId = TaoKeApiUtil.getRelationId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                  TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 渠道ID
            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 {
@@ -116,27 +134,46 @@
               LogHelper.test(e.getMsg());
               errCode = 5;
            }
            final String relationId2  = relationId;
            // 异步申请会员ID
            ThreadUtil.run(new Runnable() {
               @Override
               public void run() {
                  String specialId = TaoKeApiUtil.getSpecialId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                        TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
                  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(uid + "会员备案失败");
                  try {
                     userExtraTaoBaoInfoService.addSpecialId(uid, specialId, taoBaoUid, name, true);
                     if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId2))
                        userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
                  } catch (UserExtraTaoBaoInfoException e) {
                     LogHelper.test(e.getMsg());
                  }
               }
            });
            //稍作延迟
            Thread.sleep(50);
         } else if ("zigou".equalsIgnoreCase(source)) {
            String specialId = TaoKeApiUtil.getSpecialId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                  TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
            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 + "会员备案失败");
@@ -147,29 +184,47 @@
               errCode = 5;
            }
            final String specialId2 = specialId;
            // 异步申请渠道ID
            ThreadUtil.run(new Runnable() {
               @Override
               public void run() {
                  String relationId = TaoKeApiUtil.getRelationId(accessToken, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
                        TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 渠道ID
                  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(uid + "渠道备案失败");
                  try {
                     userExtraTaoBaoInfoService.addRelationId(uid, relationId, taoBaoUid, name, true);
                     if (!StringUtil.isNullOrEmpty(specialId2) && !StringUtil.isNullOrEmpty(relationId))
                        userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindTaoBao, taoBaoUid);
                  } catch (UserExtraTaoBaoInfoException e) {
                     LogHelper.test(e.getMsg());
                  }
               }
            });
            //稍作延迟
            Thread.sleep(50);
         } else if ("bind".equalsIgnoreCase(source)) {
            boolean bindInfo = true;
            // 绑定淘宝:V1.5.3
            String relationId = TaoKeApiUtil.getRelationId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
                  TaoBaoConstant.TAOBAO_AUTH_APPSECRET);// 渠道ID
            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;
@@ -177,8 +232,12 @@
            String specialId = null;
            if (bindInfo) {
               specialId = TaoKeApiUtil.getSpecialId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
                     TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
               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;
@@ -186,11 +245,17 @@
            }
            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;
@@ -215,11 +280,7 @@
      } catch (Exception e) {
         errCode = 4;
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
         LogHelper.errorDetailInfo(e);
      }
      try {
@@ -258,7 +319,7 @@
   }
   private void closeWebPage(PrintWriter out) {
      String script = "<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.finishPage();}</script>";
      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);
   }