|
|
@@ -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()+"");
|