Pārlūkot izejas kodu

三方服务-调整大淘客功能

sunxbiao 8 mēneši atpakaļ
vecāks
revīzija
9ecf213cfd

+ 6 - 0
thirdPartyWares_service/pom.xml

@@ -52,6 +52,12 @@
52 52
             <artifactId>pagehelper-spring-boot-starter</artifactId>
53 53
             <version>1.3.1</version>
54 54
         </dependency>
55
+        <dependency>
56
+            <groupId>cn.hutool</groupId>
57
+            <artifactId>hutool-all</artifactId>
58
+            <version>5.3.5</version>
59
+            <scope>compile</scope>
60
+        </dependency>
55 61
 
56 62
     </dependencies>
57 63
     <build>

+ 43 - 5
thirdPartyWares_service/src/main/java/com/bjtdba/thirdPartWares/controller/TaobaoCallback.java

@@ -1,16 +1,22 @@
1 1
 package com.bjtdba.thirdPartWares.controller;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
3 4
 import com.bjtdba.entity.thirdPartyWares.UserThird;
4 5
 import com.bjtdba.thirdPartWares.dao.UserThirdDao;
5 6
 import com.bjtdba.thirdPartWares.service.TaobaoService;
6 7
 import lombok.extern.slf4j.Slf4j;
7 8
 import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.beans.factory.annotation.Value;
8 10
 import org.springframework.web.bind.annotation.GetMapping;
9 11
 import org.springframework.web.bind.annotation.RequestMapping;
10 12
 import org.springframework.web.bind.annotation.RestController;
11 13
 import org.springframework.web.servlet.ModelAndView;
12 14
 
13 15
 import java.io.IOException;
16
+import java.net.URLDecoder;
17
+import java.nio.charset.StandardCharsets;
18
+import java.util.Base64;
19
+
14 20
 @Slf4j
15 21
 @RestController
16 22
 @RequestMapping("taobaoService")
@@ -20,21 +26,53 @@ public class TaobaoCallback {
20 26
     private TaobaoService taobaoService;
21 27
     @Autowired
22 28
     private UserThirdDao userThirdDao;
29
+    @Value("${TB.AUTH_REDIRECT_URI}")
30
+    private String authRedirectUri;
23 31
 
24 32
     /**
25 33
      * 淘宝回调
26 34
      */
27 35
 
28 36
     @GetMapping("/loginToken")
29
-    public ModelAndView getTaobaoAuthorizedLoginToken(String code,String state) throws IOException {
30
-        taobaoService.getTaobaoAuthorizedLoginToken(code,state);
31
-        return new ModelAndView("redirect:https://app.bjtdba.com/taobao_service/baichuan.html");
37
+    public ModelAndView getTaobaoAuthorizedLoginToken(String code, String state) throws IOException {
38
+        String decodedState = "";
39
+        if (state != null) {
40
+            decodedState = URLDecoder.decode(state, "UTF-8");
41
+            // Base64 解码
42
+            byte[] decodedBytes = Base64.getDecoder().decode(decodedState);
43
+            decodedState = new String(decodedBytes, StandardCharsets.UTF_8);
44
+        }
45
+        taobaoService.getTaobaoAuthorizedLoginToken(code, decodedState);
46
+        String viewName = "redirect:" + authRedirectUri;
47
+
48
+        if (!decodedState.isEmpty()) {
49
+            JSONObject stateObject = JSONObject.parseObject(decodedState);
50
+
51
+            // 构建最终 URL
52
+            StringBuilder finalUrlBuilder = new StringBuilder(viewName);
53
+            boolean firstParam = true;
54
+
55
+            for (String key : stateObject.keySet()) {
56
+                String value = stateObject.getString(key);
57
+                if (firstParam) {
58
+                    finalUrlBuilder.append("?");
59
+                    firstParam = false;
60
+                } else {
61
+                    finalUrlBuilder.append("&");
62
+                }
63
+                finalUrlBuilder.append(key).append("=").append(value);
64
+            }
65
+            viewName = finalUrlBuilder.toString();
66
+            System.out.println(stateObject.toJSONString());
67
+            System.out.println(viewName);
68
+        }
69
+        return new ModelAndView(viewName);
32 70
     }
33 71
 
34 72
     @GetMapping("/thridUser")
35
-    public  void thridUser(String time,String Pid,String Pidname,String Type,String Uid){
73
+    public void thridUser(String time, String Pid, String Pidname, String Type, String Uid) {
36 74
         log.info("===========+? Create_time,? Pid,? Pid_name,? Type,String Uid", time, Pid, Pidname, Type, Uid);
37
-        UserThird userThird=new UserThird();
75
+        UserThird userThird = new UserThird();
38 76
         userThird.setCreate_time(time);
39 77
         userThird.setPid(Pid);
40 78
         userThird.setPid_name(Pidname);

+ 1 - 1
thirdPartyWares_service/src/main/java/com/bjtdba/thirdPartWares/controller/TaobaoController.java

@@ -43,7 +43,7 @@ public class TaobaoController {
43 43
      */
44 44
     @PostMapping("/dtkchangeLink")
45 45
     public Object dtkchangeLink(@RequestBody Map<String,String> map){
46
-        return taobaoService.dtkchangeLink(map.get("id"),map.get("uid"));
46
+        return taobaoService.dtkchangeLink(map.get("id"),map.get("uid"),map.get("source"));
47 47
     }
48 48
 
49 49
 

+ 1 - 1
thirdPartyWares_service/src/main/java/com/bjtdba/thirdPartWares/service/TaobaoService.java

@@ -14,7 +14,7 @@ public interface TaobaoService {
14 14
 
15 15
     Object selectWaresDetail(String id, String goodsId, String uid) throws IOException;
16 16
 
17
-    Object dtkchangeLink(String id, String uid);
17
+    Object dtkchangeLink(String id, String uid, String source);
18 18
 
19 19
     Object saveThirdPartGood();
20 20
 

+ 63 - 14
thirdPartyWares_service/src/main/java/com/bjtdba/thirdPartWares/service/impl/TaobaoServiceImpl.java

@@ -18,8 +18,11 @@ import org.springframework.beans.factory.annotation.Value;
18 18
 import org.springframework.stereotype.Service;
19 19
 
20 20
 import java.io.IOException;
21
+import java.io.UnsupportedEncodingException;
21 22
 import java.math.BigDecimal;
22 23
 import java.net.URL;
24
+import java.net.URLEncoder;
25
+import java.nio.charset.StandardCharsets;
23 26
 import java.text.DateFormat;
24 27
 import java.text.ParseException;
25 28
 import java.text.SimpleDateFormat;
@@ -197,7 +200,7 @@ public class TaobaoServiceImpl implements TaobaoService {
197 200
      public Object saveThirdPartGood(){
198 201
         //定时执行180次3.6万条数据存入数据库
199 202
         int aa=1;
200
-        for(int i=1;i<=1800;i++){
203
+        for(int i=1;i<=180;i++){
201 204
             log.info("=================================开始循环第"+i+"次=========================");
202 205
             List<ThirdPartyWares> thirdPartyWaresList =selectTaobaoWaresList(i+"",200+"",null);
203 206
             //用来接收json的值
@@ -349,7 +352,7 @@ public class TaobaoServiceImpl implements TaobaoService {
349 352
      * @throws
350 353
      * @throws IOException
351 354
      */
352
-    public Object dtkchangeLink(String id, String uid) {
355
+    public Object dtkchangeLink(String id, String uid, String source) {
353 356
         Map<String,Object> data=new HashMap<String,Object>();
354 357
         /**
355 358
          * 判断该用户是否已经授权淘宝  rrx_user_third
@@ -376,19 +379,48 @@ public class TaobaoServiceImpl implements TaobaoService {
376 379
                 return ResponseUtil.fail("该商品已下架或不存在~");
377 380
             }
378 381
             JSONObject jsonObjects = JSONObject.parseObject(JSONObject.parseObject(sendGet).get("data").toString());
379
-            Raw raw = new Raw();
380
-            raw.setCouponEndTime((String) jsonObjects.get("couponEndTime"));
381
-            raw.setCouponInfo((String) jsonObjects.get("couponInfo"));
382
-            raw.setCouponStartTime((String) jsonObjects.get("couponStartTime"));
383
-            raw.setLongTpwd((String) jsonObjects.get("longTpwd"));
384
-            raw.setTpwd((String) jsonObjects.get("tpwd"));
382
+//            Raw raw = new Raw();
383
+//            raw.setCouponEndTime((String) jsonObjects.get("couponEndTime"));
384
+//            raw.setCouponInfo((String) jsonObjects.get("couponInfo"));
385
+//            raw.setCouponStartTime((String) jsonObjects.get("couponStartTime"));
386
+//            raw.setLongTpwd((String) jsonObjects.get("longTpwd"));
387
+//            raw.setTpwd((String) jsonObjects.get("tpwd"));
388
+            data.put("data", jsonObjects);
385 389
             data.put("link", jsonObjects.get("shortUrl"));
386 390
             data.put("code",1);
387 391
         }else{
388 392
             //走淘宝获取pid接口  https://oauth.taobao.com/authorize?response_type=code&client_id=CLIENTID&redirect_uri=REDIRECTURI&state=STATE&view=web
389
-            String link = tbHost.replace("CLIENTID",tbAppKey).replace("REDIRECTURI",redirecturi).replace("STATE",uid);
390
-            data.put("link",link);
391
-            data.put("code",0);
393
+
394
+            JSONObject jsonObject = new JSONObject();
395
+            jsonObject.put("uid", uid);
396
+            jsonObject.put("itemId", id);
397
+            jsonObject.put("source", source);
398
+            try {
399
+                String base64State = Base64.getEncoder().encodeToString(jsonObject.toString().getBytes(StandardCharsets.UTF_8));
400
+                String encodedState = URLEncoder.encode(base64State, "UTF-8");
401
+                String encodedRedirectUri = URLEncoder.encode(redirecturi, "UTF-8");
402
+                System.out.println(encodedState);
403
+                String link = tbHost.replace("CLIENTID", tbAppKey)
404
+                        .replace("REDIRECTURI", encodedRedirectUri)
405
+                        .replace("STATE", encodedState);
406
+
407
+                System.out.println("生成的链接: " + link);
408
+
409
+                data.put("link",link);
410
+                data.put("code",0);
411
+            } catch (UnsupportedEncodingException e) {
412
+                // 处理编码异常
413
+                e.printStackTrace();
414
+                return null;
415
+            }
416
+
417
+//            JSONObject jsonObject = new JSONObject();
418
+//            jsonObject.put("uid", uid);
419
+//            jsonObject.put("itemId", id);
420
+//            jsonObject.put("source", source);
421
+//            String link = tbHost.replace("CLIENTID",tbAppKey).replace("REDIRECTURI",redirecturi).replace("STATE",jsonObject.toString());
422
+
423
+
392 424
         }
393 425
         return ResponseUtil.ok(data);
394 426
     }
@@ -406,14 +438,22 @@ public class TaobaoServiceImpl implements TaobaoService {
406 438
         params.put("sign_method", "hmac");
407 439
         params.put("code", code);
408 440
         params.put("sign", SignTop.signTopRequest(params, tbkAppSecret, "hmac"));
441
+        System.out.println("***************taobao.top.auth.token.create start *****************");
442
+        System.out.println(params.toString());
409 443
         String a = SignTop.callApi(new URL("https://eco.taobao.com/router/rest"), params);
444
+        System.out.println("原始响应字符串: " + a);
410 445
         JSONObject jsonObjects = JSONObject.parseObject(a);
446
+        System.out.println("解析为JSONObject后: " + jsonObjects.toJSONString());
447
+        System.out.println("***************taobao.top.auth.token.create* end****************");
411 448
         Object token = JSONObject.parseObject(JSONObject.parseObject(jsonObjects.get("top_auth_token_create_response").toString()).get("token_result").toString()).get("access_token");
412 449
         //备案
413 450
         demo(token.toString(),state);
414 451
     }
415 452
     //备案
416 453
     private void demo(String token,String state) throws IOException {
454
+
455
+        JSONObject stateObject = JSONObject.parseObject(state);
456
+
417 457
         Map<String, String> params = new HashMap<String, String>();
418 458
         // 公共参数
419 459
         params.put("method", "taobao.tbk.sc.publisher.info.save");
@@ -425,20 +465,29 @@ public class TaobaoServiceImpl implements TaobaoService {
425 465
         params.put("v", "2.0");
426 466
         params.put("sign_method","hmac");
427 467
         // 业务参数
428
-        params.put("inviter_code","E7LRL8");
468
+        // 会员
469
+        // params.put("inviter_code","RQHQ8Z");
470
+        // 渠道
471
+        params.put("inviter_code","BCS4V5");
429 472
         params.put("info_type","1");
430
-        params.put("note","储_"+state);
473
+        params.put("note","幸福_"+stateObject.get("uid"));
431 474
         // 签名参数
432 475
         params.put("sign", SignTop.signTopRequest(params, tbkAppSecret, "hmac"));
433 476
         // 请用API
477
+        System.out.println("***************taobao.tbk.sc.publisher.info.save start *****************");
434 478
         System.out.println(params.toString());
435 479
         String callApi = SignTop.callApi(new URL("https://eco.taobao.com/router/rest"), params);
480
+        // 打印原始字符串
481
+        System.out.println("原始响应字符串: " + callApi);
436 482
         JSONObject jsonObjects = JSONObject.parseObject(callApi);
483
+        // 打印解析后的JSONObject(使用toString,但通常toString没有格式化,我们可以用toJSONString来美化)
484
+        System.out.println("解析为JSONObject后: " + jsonObjects.toJSONString());
485
+        System.out.println("***************taobao.tbk.sc.publisher.info.save end *****************");
437 486
         String data = JSONObject.parseObject(jsonObjects.get("tbk_sc_publisher_info_save_response").toString()).get("data").toString();
438 487
         Object account_name = JSONObject.parseObject(data).get("account_name");
439 488
         Object relation_id = JSONObject.parseObject(data).get("relation_id");
440 489
         UserThird userThird = new UserThird();
441
-        userThird.setUid(state);
490
+        userThird.setUid((String) stateObject.get("uid"));
442 491
         userThird.setPid(relation_id.toString());
443 492
         userThird.setPid_name(account_name.toString());
444 493
         userThird.setCreate_time(new Date().getTime()+"");

+ 3 - 1
thirdPartyWares_service/src/main/resources/application-dev.yml

@@ -37,4 +37,6 @@ eureka:
37 37
     prefer-ip-address: true #使用ip地址注册
38 38
 
39 39
 
40
-TB.REDIRECTURI: https://app.bjtdba.com/taobao_service/taobaoService/loginToken
40
+TB.REDIRECTURI: https://testapi.hxxfb.com/taobao_service/taobaoService/loginToken
41
+
42
+TB.AUTH_REDIRECT_URI: https://testapi.hxxfb.com/taobao_service/baichuan.html

+ 3 - 1
thirdPartyWares_service/src/main/resources/application-pro.yml

@@ -37,4 +37,6 @@ eureka:
37 37
     prefer-ip-address: true #使用ip地址注册
38 38
 
39 39
 
40
-TB.REDIRECTURI: https://app.bjtdba.com/taobao_service/taobaoService/loginToken
40
+TB.REDIRECTURI: https://api.hxxfb.com/taobao_service/taobaoService/loginToken
41
+
42
+TB.AUTH_REDIRECT_URI: https://api.hxxfb.com/taobao_service/baichuan.html

+ 7 - 7
thirdPartyWares_service/src/main/resources/application.yml

@@ -26,17 +26,17 @@ pagehelper:
26 26
 #DTK.HOST: https://openapi.dataoke.com
27 27
 
28 28
 
29
-DTK.APPSECRET: 0e4f0cdf9b1a58d763bcb956b56578da
30
-DTK.APPKEY: 6002a6fd58162
31
-DTK.PID: mm_1411990095_2149000369_111007900247
29
+DTK.APPSECRET: 6b701ad73c7cc4c2de56a4afcb876af2
30
+DTK.APPKEY: 691e84c785246
31
+DTK.PID: mm_9436146813_3362200454_116174700455
32 32
 DTK.HOST: https://openapi.dataoke.com
33 33
 
34 34
 
35 35
 #淘宝
36
-TB.APPKEY: 31940963
37
-TB.APPSECRET: f8437ad5821d697bae35f3fa613b6370
38
-TB.ADZONEID: 111007900247
39
-TB.HOST: https://oauth.taobao.com/authorize?response_type=code&client_id=CLIENTID&redirect_uri=REDIRECTURI&state=STATE&view=web
36
+TB.APPKEY: 35214206
37
+TB.APPSECRET: b4ec4e885fb4a189d3beb475fbb15dc6
38
+TB.ADZONEID: 116174700455
39
+TB.HOST: https://oauth.taobao.com/authorize?response_type=code&client_id=CLIENTID&redirect_uri=REDIRECTURI&state=STATE&view=wap
40 40
 
41 41
 
42 42
 

+ 322 - 7
thirdPartyWares_service/src/main/resources/static/baichuan.html

@@ -1,19 +1,334 @@
1 1
 <!DOCTYPE html>
2 2
 <html lang="zh-CN">
3
+
3 4
 <head>
4
-<meta charset="utf-8">
5
-<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
6
-<title></title>
5
+    <meta charset="utf-8">
6
+    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
7
+    <title>授权成功</title>
8
+    <style>
9
+        * {
10
+            margin: 0;
11
+            padding: 0;
12
+            box-sizing: border-box;
13
+        }
14
+
15
+        body {
16
+            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
17
+            background: linear-gradient(135deg, #ff5000 0%, #ff7a45 100%);
18
+            min-height: 100vh;
19
+            display: flex;
20
+            align-items: center;
21
+            justify-content: center;
22
+            padding: 20px;
23
+        }
24
+
25
+        .container {
26
+            background: white;
27
+            border-radius: 20px;
28
+            box-shadow: 0 20px 40px rgba(255, 80, 0, 0.2);
29
+            padding: 40px 30px;
30
+            text-align: center;
31
+            max-width: 90%;
32
+            width: 350px;
33
+            animation: fadeIn 0.5s ease-out;
34
+        }
35
+
36
+        @keyframes fadeIn {
37
+            from {
38
+                opacity: 0;
39
+                transform: translateY(20px);
40
+            }
41
+
42
+            to {
43
+                opacity: 1;
44
+                transform: translateY(0);
45
+            }
46
+        }
47
+
48
+        .success-icon {
49
+            width: 80px;
50
+            height: 80px;
51
+            background: linear-gradient(135deg, #ff5000 0%, #ff7a45 100%);
52
+            border-radius: 50%;
53
+            display: flex;
54
+            align-items: center;
55
+            justify-content: center;
56
+            margin: 0 auto 20px;
57
+        }
58
+
59
+        .success-icon::after {
60
+            content: "✓";
61
+            color: white;
62
+            font-size: 40px;
63
+            font-weight: bold;
64
+        }
65
+
66
+        h1 {
67
+            color: #333;
68
+            font-size: 24px;
69
+            margin-bottom: 10px;
70
+        }
71
+
72
+        p {
73
+            color: #666;
74
+            font-size: 16px;
75
+            line-height: 1.5;
76
+            margin-bottom: 25px;
77
+        }
78
+
79
+        .taokouling-box {
80
+            background: #fff9f5;
81
+            border: 1px solid #ffebe1;
82
+            border-radius: 12px;
83
+            padding: 15px;
84
+            margin: 25px 0;
85
+            position: relative;
86
+        }
87
+
88
+        .taokouling-text {
89
+            font-size: 18px;
90
+            font-weight: bold;
91
+            color: #ff5000;
92
+            word-break: break-all;
93
+            user-select: all;
94
+        }
95
+
96
+        .copy-btn {
97
+            background: linear-gradient(135deg, #ff5000 0%, #ff7a45 100%);
98
+            color: white;
99
+            border: none;
100
+            border-radius: 50px;
101
+            padding: 15px 25px;
102
+            font-size: 16px;
103
+            font-weight: bold;
104
+            cursor: pointer;
105
+            width: 100%;
106
+            transition: all 0.3s ease;
107
+            margin-top: 10px;
108
+            box-shadow: 0 4px 15px rgba(255, 80, 0, 0.3);
109
+        }
110
+
111
+        .copy-btn:hover {
112
+            transform: translateY(-2px);
113
+            box-shadow: 0 10px 20px rgba(255, 80, 0, 0.4);
114
+        }
115
+
116
+        .copy-btn:active {
117
+            transform: translateY(0);
118
+        }
119
+
120
+        .loading {
121
+            display: none;
122
+            margin: 20px auto;
123
+        }
124
+
125
+        .spinner {
126
+            border: 3px solid #ffebe1;
127
+            border-top: 3px solid #ff5000;
128
+            border-radius: 50%;
129
+            width: 30px;
130
+            height: 30px;
131
+            animation: spin 1s linear infinite;
132
+            margin: 0 auto;
133
+        }
134
+
135
+        @keyframes spin {
136
+            0% {
137
+                transform: rotate(0deg);
138
+            }
139
+
140
+            100% {
141
+                transform: rotate(360deg);
142
+            }
143
+        }
144
+
145
+        .message {
146
+            margin-top: 15px;
147
+            padding: 10px;
148
+            border-radius: 8px;
149
+            font-size: 14px;
150
+            display: none;
151
+        }
152
+
153
+        .success-message {
154
+            background-color: #fff5e6;
155
+            color: #cc4100;
156
+            border: 1px solid #ffd0b3;
157
+        }
158
+
159
+        .error-message {
160
+            background-color: #ffece6;
161
+            color: #cc3200;
162
+            border: 1px solid #ffb3a0;
163
+        }
164
+
165
+        .redirect-info {
166
+            font-size: 14px;
167
+            color: #ff9c66;
168
+            margin-top: 20px;
169
+        }
170
+    </style>
7 171
 </head>
172
+
8 173
 <body>
9
-<div>
10
-    授权成功,请稍等...
174
+<div class="container">
175
+    <div class="success-icon"></div>
176
+    <h1>授权成功</h1>
177
+    <p>恭喜您已成功授权,即将为您跳转至淘宝APP</p>
178
+
179
+    <div class="loading" id="loading">
180
+        <div class="spinner"></div>
181
+        <p>正在获取淘口令...</p>
182
+    </div>
183
+
184
+    <div class="taokouling-box" id="taokoulingBox" style="display: none;">
185
+        <div class="taokouling-text" id="taokoulingText"></div>
186
+    </div>
187
+
188
+    <button class="copy-btn" id="copyBtn" style="display: none;" onclick="copyTaokouling()">
189
+        复制淘口令并打开淘宝
190
+    </button>
191
+
192
+    <div class="message" id="message"></div>
193
+
194
+    <div class="redirect-info">
195
+        如果未自动跳转,请手动打开淘宝APP
196
+    </div>
11 197
 </div>
198
+
12 199
 <script type="text/javascript" src="https://g.alicdn.com/mtb/lib_BC/0.1.0/p/index/index.js"></script>
13 200
 <script type="text/javascript">
201
+    // 页面加载完成后执行
14 202
     window.onload = function () {
15
-        android.back();
203
+        // 显示加载状态
204
+        document.getElementById('loading').style.display = 'block';
205
+
206
+        // 获取URL参数
207
+        const urlParams = new URLSearchParams(window.location.search);
208
+        const id = urlParams.get('uid');
209
+        const itemid = urlParams.get('itemId');
210
+        const source = urlParams.get('source');
211
+
212
+        // 发起HTTP请求获取淘口令
213
+        fetchTaokouling(id, itemid, source);
214
+    };
215
+
216
+    // 从服务器获取淘口令
217
+    function fetchTaokouling(id, itemid, source) {
218
+        // 构造请求URL
219
+        const apiUrl = `https://testapi.hxxfb.com/gateway/thirdPartyWares_service/taobao_service/dtkchangeLink`;
220
+
221
+        // 构造请求参数
222
+        const requestData = {
223
+            method: 'POST',
224
+            headers: {
225
+                'Content-Type': 'application/json'
226
+            },
227
+            body: JSON.stringify({
228
+                uid: id,
229
+                id: itemid
230
+            })
231
+        };
232
+
233
+        // 发起请求
234
+        fetch(apiUrl, requestData)
235
+            .then(response => {
236
+                if (!response.ok) {
237
+                    throw new Error('网络响应错误');
238
+                }
239
+                return response.json();
240
+            })
241
+            .then(data => {
242
+                // 检查source是否为xiaochengxu
243
+                if (source == "xiaochengxu") {
244
+                    // 如果是小程序来源,直接跳转到shortUrl
245
+                    if (data.data && data.data.data && data.data.data.shortUrl) {
246
+                        window.location.href = data.data.data.shortUrl;
247
+                    } else {
248
+                        throw new Error('未获取到短链接');
249
+                    }
250
+                } else {
251
+                    // 检查是否有淘口令
252
+                    if (data.data && data.data.data && data.data.data.longTpwd) {
253
+                        // 隐藏加载状态
254
+                        document.getElementById('loading').style.display = 'none';
255
+
256
+                        // 显示淘口令和按钮
257
+                        document.getElementById('taokoulingText').textContent = data.data.data.longTpwd;
258
+                        document.getElementById('taokoulingBox').style.display = 'block';
259
+                        document.getElementById('copyBtn').style.display = 'block';
260
+
261
+                        // 保存淘口令到全局变量
262
+                        window.taokouling = data.data.data.longTpwd;
263
+                    } else {
264
+                        throw new Error('未获取到淘口令');
265
+                    }
266
+                }
267
+            })
268
+            .catch(error => {
269
+                console.error('请求失败:', error);
270
+                showMessage('获取信息失败,请稍后重试', 'error');
271
+                document.getElementById('loading').style.display = 'none';
272
+            });
273
+    }
274
+
275
+    // 复制淘口令并跳转到淘宝
276
+    function copyTaokouling() {
277
+        try {
278
+            // 创建临时文本区域用于复制
279
+            const textArea = document.createElement("textarea");
280
+            textArea.value = window.taokouling;
281
+            document.body.appendChild(textArea);
282
+            textArea.select();
283
+            document.execCommand('copy');
284
+            document.body.removeChild(textArea);
285
+
286
+            // 显示成功消息
287
+            showMessage('淘口令已复制到剪贴板,请在淘宝APP中使用', 'success');
288
+
289
+            // 延迟跳转到淘宝APP
290
+            setTimeout(() => {
291
+                // 尝试跳转到淘宝APP
292
+                if (isMobile()) {
293
+                    // 移动端尝试跳转到淘宝APP
294
+                    window.location.href = "taobao://";
295
+                } else {
296
+                    // PC端提示用户打开淘宝
297
+                    alert("请打开淘宝APP使用淘口令");
298
+                }
299
+
300
+                // 返回原应用(如果支持)
301
+                try {
302
+                    android.back();
303
+                } catch (e) {
304
+                    console.log("无法调用原生返回方法");
305
+                }
306
+            }, 1500);
307
+
308
+        } catch (err) {
309
+            showMessage('复制失败,请手动复制淘口令', 'error');
310
+            console.error('复制失败:', err);
311
+        }
312
+    }
313
+
314
+    // 显示消息
315
+    function showMessage(text, type) {
316
+        const messageEl = document.getElementById('message');
317
+        messageEl.textContent = text;
318
+        messageEl.className = 'message ' + (type === 'success' ? 'success-message' : 'error-message');
319
+        messageEl.style.display = 'block';
320
+
321
+        // 3秒后隐藏消息
322
+        setTimeout(() => {
323
+            messageEl.style.display = 'none';
324
+        }, 3000);
325
+    }
326
+
327
+    // 判断是否为移动设备
328
+    function isMobile() {
329
+        return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
16 330
     }
17 331
 </script>
18 332
 </body>
19
-</html>
333
+
334
+</html>