| | |
| | | package com.yeshi.fanli.controller;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.io.IOException;
|
| | | 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.UserInfo;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionAuthRecord;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionAuthRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.util.AESUtil;
|
| | |
| | | private TaoBaoUnionAuthRecordService taoBaoUnionAuthRecordService;
|
| | |
|
| | | @RequestMapping(value = "tb")
|
| | | public void tb(String code, String state, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(code) || StringUtil.isNullOrEmpty(state))
|
| | | 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/apppage/flq_bonusState.html?code=1");
|
| | | } catch (IOException e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | return;
|
| | | }
|
| | | String stateStr = AESUtil.decrypt(state, Constant.UIDAESKEY);
|
| | | int errCode = 0;
|
| | | if (StringUtil.isNullOrEmpty(stateStr)) {
|
| | |
| | | JSONObject json = JSONObject.fromObject(stateStr);
|
| | | Long time = json.optLong("t");
|
| | | Long uid = json.optLong("u");
|
| | | String source = json.optString("s");
|
| | | if (System.currentTimeMillis() - time > 1000 * 60 * 10L) {
|
| | | // 过时
|
| | | errCode = 2;
|
| | |
| | | String openUid = data.optString("taobao_open_uid");
|
| | | String taoBaoUid = data.optString("taobao_user_id");
|
| | | String nickName = data.optString("taobao_user_nick");
|
| | |
|
| | | // LogHelper.test("uid:" + uid + "\n accessToken:" + accessToken);
|
| | |
|
| | | // 获取渠道ID与会员ID
|
| | | if ("share".equalsIgnoreCase(source)) {
|
| | | String relationId = TaoKeApiUtil.getRelationId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
|
| | | Constant.TAOBAO_AUTH_APPSECRET);// 渠道ID
|
| | | if (StringUtil.isNullOrEmpty(relationId))
|
| | | LogHelper.test(uid + "渠道备案失败");
|
| | | userExtraTaoBaoInfoService.addRelationId(uid, relationId, taoBaoUid, true);
|
| | | } else {
|
| | | String specialId = TaoKeApiUtil.getSpecialId(accessToken, Constant.TAOBAO_AUTH_APPKEY,
|
| | | Constant.TAOBAO_AUTH_APPSECRET);
|
| | | if (StringUtil.isNullOrEmpty(specialId))
|
| | | LogHelper.test(uid + "会员备案失败");
|
| | | userExtraTaoBaoInfoService.addSpecialId(uid, specialId, taoBaoUid, true);
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(nickName))
|
| | | try {
|
| | | nickName = URLDecoder.decode(nickName, "UTF-8");
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // userExtraTaoBaoInfoService.addRelationId(uid, relationId);
|
| | | TaoBaoUnionAuthRecord record = new TaoBaoUnionAuthRecord();
|
| | | record.setUser(new UserInfo(uid));
|
| | | record.setTaoBaoOpenUid(openUid);
|
| | |
| | | taoBaoUnionAuthRecordService.addAuthRecord(record);
|
| | | } catch (Exception e) {
|
| | | errCode = 4;
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | out.print("<html><body>绑定错误:错误码(" + errCode + ")</body></html>");
|
| | | try {
|
| | | if (errCode == 0)// 成功
|
| | | {
|
| | | if ("share".equalsIgnoreCase(source))
|
| | | response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_bonusState.html?code=0");
|
| | | else
|
| | | response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_rebateState.html?code=0");
|
| | | } else {// 失败
|
| | | if ("share".equalsIgnoreCase(source))
|
| | | response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_bonusState.html?code=1");
|
| | | else
|
| | | response.sendRedirect("http://apph5.yeshitv.com/apppage/flq_rebateState.html?code=1");
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|