yujian
2019-04-08 1da17d215d48e3e3aa9e8d7a3ef526904764f408
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.yeshi.fanli.controller.client;
 
import java.io.PrintWriter;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.encrypt.DESUtil;
 
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("api/v1/userauth")
public class UserAuthController {
 
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
 
    @Resource
    private ConfigService configService;
 
    /**
     * 获取淘宝授权信息
     * 
     * @param acceptData
     * @param uid
     * @param source
     * @param out
     */
    @RequestMapping(value = "getTaoBaoAuthInfo", method = RequestMethod.POST)
    public void getUserConfig(AcceptData acceptData, Long uid, String source, Boolean first, PrintWriter out) {
 
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(2, "用户未登录"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(source)) {
            out.print(JsonUtil.loadFalseResult(3, "来源错误"));
            return;
        }
 
        if (first == null) {
            out.print(JsonUtil.loadFalseResult(4, "请传first"));
            return;
        }
 
        if (!"1".equalsIgnoreCase(configService.get("open_speical_and_relation_apply"))) {
            out.print(JsonUtil.loadFalseResult(1, "暂不开放申请"));
            return;
        }
        
    
            
            
        
 
        //
        UserExtraTaoBaoInfo user = userExtraTaoBaoInfoService.getByUid(uid);
        if ("share".equalsIgnoreCase(source)) {
            if (user != null && !StringUtil.isNullOrEmpty(user.getRelationId()) && user.getRelationValid()) {
                out.print(JsonUtil.loadFalseResult(1, "无需授权"));
                return;
            }
 
        } else {
            if (user != null && !StringUtil.isNullOrEmpty(user.getSpecialId()) && user.getSpecialValid()) {
                out.print(JsonUtil.loadFalseResult(1, "无需授权"));
                return;
            }
        }
 
        String link = TaoBaoUtil.getTaoBaoUnionAuthUrl(Constant.TAOBAO_AUTH_APPKEY,
                "http://api.flqapp.com/fanli/client/v1/auth/callback/tb", uid, source);
 
        String orderJS = "var orderId= document.getElementById('tp-bought-root').getElementsByClassName('js-order-container')[0].getElementsByTagName('div')[0].getAttribute('data-id');";
        orderJS += "if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href='yestv://taobaoorder#'+orderId;} else {window.handle.showOrder(orderId)}";
        JSONObject data = new JSONObject();
        data.put("authLink", link);
        try {
            data.put("orderJS", DESUtil.encode(orderJS, StringUtil.getBase64String("YeShiFANLI889*+"),
                    StringUtil.getBase64String("*M#34f?,")));
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        data.put("orderUrl", "https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm");
        if (first)
            out.print(JsonUtil.loadTrueResult(data));
        else
            out.print(JsonUtil.loadTrue(0, data, "淘宝授权未成功,请稍后再试"));
    }
    
    
    /**
     * 获取淘宝授权信息
     * 
     * @param acceptData
     * @param uid
     * @param source
     * @param out
     */
    @RequestMapping(value = "getTaoBaoAuthInfoNew", method = RequestMethod.POST)
    public void getTaoBaoAuthInfoNew(AcceptData acceptData, Long uid, String source, Boolean first, PrintWriter out) {
 
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(2, "用户未登录"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(source)) {
            out.print(JsonUtil.loadFalseResult(3, "来源错误"));
            return;
        }
 
        if (first == null) {
            out.print(JsonUtil.loadFalseResult(4, "请传first"));
            return;
        }
 
        if (!"1".equalsIgnoreCase(configService.get("open_speical_and_relation_apply"))) {
            out.print(JsonUtil.loadFalseResult(1, "暂不开放申请"));
            return;
        }
 
        //
        UserExtraTaoBaoInfo user = userExtraTaoBaoInfoService.getByUid(uid);
        if ("share".equalsIgnoreCase(source)) {
            if (user != null && !StringUtil.isNullOrEmpty(user.getRelationId()) && user.getRelationValid()) {
                out.print(JsonUtil.loadFalseResult(1, "无需授权"));
                return;
            }
 
        } else if ("zigou".equalsIgnoreCase(source)) {
            if (user != null && !StringUtil.isNullOrEmpty(user.getSpecialId()) && user.getSpecialValid()) {
                out.print(JsonUtil.loadFalseResult(1, "无需授权"));
                return;
            }
        }
 
        String link = TaoBaoUtil.getTaoBaoUnionAuthUrl(Constant.TAOBAO_AUTH_APPKEY,
                "http://api.flqapp.com/fanli/client/v1/auth/callback/tb", uid, source);
 
        String orderJS = "var orderId= document.getElementById('tp-bought-root').getElementsByClassName('js-order-container')[0].getElementsByTagName('div')[0].getAttribute('data-id');";
        orderJS += "if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {window.location.href='yestv://taobaoorder#'+orderId;} else {window.handle.showOrder(orderId)}";
        JSONObject data = new JSONObject();
        data.put("authLink", link);
        try {
            data.put("orderJS", DESUtil.encode(orderJS, StringUtil.getBase64String("YeShiFANLI889*+"),
                    StringUtil.getBase64String("*M#34f?,")));
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        data.put("orderUrl", "https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm");
        if (first)
            out.print(JsonUtil.loadTrueResult(data));
        else
            out.print(JsonUtil.loadTrue(0, data, "淘宝授权未成功,请稍后再试"));
    }
}