Commit 67c7dedd by 吕明尚

增加抖音门店查询接口

parent 044c001f
...@@ -41,8 +41,13 @@ public class TiktokController { ...@@ -41,8 +41,13 @@ public class TiktokController {
} }
@GetMapping("/certificate/get)") @GetMapping("/certificate/get)")
public String certificateGet() { public String certificateGet(TiktokCouponDto tiktokCouponDto) {
return ""; return tiktokService.certificateGet(tiktokCouponDto);
}
@GetMapping("/poi/query")
public Object poiQuery(TiktokCouponDto tiktokCouponDto) {
return tiktokService.poiQuery(tiktokCouponDto);
} }
} }
...@@ -12,6 +12,8 @@ public class TiktokCouponDto { ...@@ -12,6 +12,8 @@ public class TiktokCouponDto {
private String code; private String code;
//门店id //门店id
private String poiId; private String poiId;
//商家账户 ID
private String accountId;
//验券准备返回的标识 //验券准备返回的标识
private String verifyToken; private String verifyToken;
//验券准备接口返回的加密抖音券码 //验券准备接口返回的加密抖音券码
......
package share.system.service; package share.system.service;
import cn.hutool.json.JSONArray;
import share.system.domain.vo.TiktokCouponDto; import share.system.domain.vo.TiktokCouponDto;
import java.util.List; import java.util.List;
...@@ -12,4 +13,8 @@ public interface TiktokService { ...@@ -12,4 +13,8 @@ public interface TiktokService {
String verify(TiktokCouponDto tiktokCouponDto); String verify(TiktokCouponDto tiktokCouponDto);
String cancel(TiktokCouponDto tiktokCouponDto); String cancel(TiktokCouponDto tiktokCouponDto);
String certificateGet(TiktokCouponDto tiktokCouponDto);
Object poiQuery(TiktokCouponDto tiktokCouponDto);
} }
...@@ -5,7 +5,9 @@ import cn.hutool.core.date.DateUtil; ...@@ -5,7 +5,9 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpGlobalConfig; import cn.hutool.http.HttpGlobalConfig;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.github.pagehelper.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -19,8 +21,9 @@ import share.system.service.TiktokService; ...@@ -19,8 +21,9 @@ import share.system.service.TiktokService;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service @Service
public class TiktokServiceImpl implements TiktokService { public class TiktokServiceImpl implements TiktokService {
...@@ -72,11 +75,15 @@ public class TiktokServiceImpl implements TiktokService { ...@@ -72,11 +75,15 @@ public class TiktokServiceImpl implements TiktokService {
//判断短链接是否以https://v.douyin.com/开头,/结尾 //判断短链接是否以https://v.douyin.com/开头,/结尾
if (tiktokCouponDto.getEncryptedData().startsWith("https://v.douyin.com/") && tiktokCouponDto.getEncryptedData().endsWith("/")) { if (tiktokCouponDto.getEncryptedData().startsWith("https://v.douyin.com/") && tiktokCouponDto.getEncryptedData().endsWith("/")) {
String encryptedData = HttpRequest.get(tiktokCouponDto.getEncryptedData()).timeout(HttpGlobalConfig.getTimeout()).execute().body(); String encryptedData = HttpRequest.get(tiktokCouponDto.getEncryptedData()).timeout(HttpGlobalConfig.getTimeout()).execute().body();
String objectId = result.substring(encryptedData.indexOf("object_id=") + "object_id=".length(), encryptedData.indexOf("&")); Pattern pattern = Pattern.compile("object_id=([^&]*)");
result = HttpRequest.get(url) Matcher matcher = pattern.matcher(encryptedData);
.contentType("application/json") if (matcher.find()) {
.header("access-token", accessToken) String objectId = matcher.group(1);
.form("encrypted_data", objectId).form("poi_id", tiktokCouponDto.getPoiId()).execute().body(); result = HttpRequest.get(url)
.contentType("application/json")
.header("access-token", accessToken)
.form("encrypted_data", objectId).form("poi_id", tiktokCouponDto.getPoiId()).execute().body();
}
} else { } else {
result = HttpRequest.get(url) result = HttpRequest.get(url)
...@@ -94,10 +101,27 @@ public class TiktokServiceImpl implements TiktokService { ...@@ -94,10 +101,27 @@ public class TiktokServiceImpl implements TiktokService {
} }
public static void main(String[] args) { public static void main(String[] args) {
String url = "<a href=\"https://www.iesdouyin.com/share/commerce/coupon/I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM/?schema_type=13&amp;object_id=I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM&amp;utm_campaign=client_scan_share&amp;app=aweme&amp;utm_medium=ios&amp;tt_from=scan_share&amp;iid=&amp;utm_source=scan_share\">Found</a>."; String url = "<a href=\"https://www.iesdouyin.com/share/commerce/" +
"coupon/I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM/" +
"?schema_type=13&amp;" +
"object_id=I0duaGdVYnp0RitYekxkNm11VHl3WUVCM2wvWXNmNEZDcXZ3aGZDYm9ka3R2VjdualNOT1VGVzMxUkxmdWowTVp2VWVBams1OFAyK3YrMm4yc0lhQm90a0hPb1ZNRFk5V3VxTkhIV3hZTHQyelByMFJ5R2YzSy9FRjZXNDgvMTBXVno1NW5MaFFOYzRQbnFtRExpZGF5YzI4aTdBK3d6dnk3eFBUTVd2VkRRZkM&amp;" +
"utm_campaign=client_scan_share&amp;" +
"app=aweme&amp;" +
"utm_medium=ios&amp;" +
"tt_from=scan_share&amp;" +
"iid=&amp;" +
"utm_source=scan_share\">Found</a>.";
//截取中间的object_id=到&amp;之间的字符串 //截取中间的object_id=到&amp;之间的字符串
String objectId = url.substring(url.indexOf("object_id=") + "object_id=".length(), url.indexOf("&amp;")); Pattern pattern = Pattern.compile("object_id=([^&]*)");
Matcher matcher = pattern.matcher(url);
if (matcher.find()) {
String objectId = matcher.group(1);
System.out.println(objectId);
} else {
System.out.println("No match found");
}
} }
@Override @Override
public String verify(TiktokCouponDto tiktokCouponDto) { public String verify(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain(); String accessToken = obtain();
...@@ -145,6 +169,62 @@ public class TiktokServiceImpl implements TiktokService { ...@@ -145,6 +169,62 @@ public class TiktokServiceImpl implements TiktokService {
return data.getStr("description"); return data.getStr("description");
} }
@Override
public String certificateGet(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/get/";
Map<String, Object> map = new HashMap<>();
map.put("encrypted_code", tiktokCouponDto.getEncryptedCode());
JSONObject jsonObject = new JSONObject(map);
String result = HttpRequest.post(url)
.contentType("application/json")
.header("access-token", accessToken)
.form("encrypted_code", jsonObject.toString()).execute().body();
JSONObject entries = new JSONObject(result);
JSONObject data = entries.getJSONObject("data");
if (!data.getStr("error_code").equals(ErrorCodeEnum.SUCCESS.getCode())) {
return data.getStr("description");
}
return data.getJSONObject("certificate").getStr("status");
}
@Override
public Object poiQuery(TiktokCouponDto tiktokCouponDto) {
String accessToken = obtain();
String url = "https://open.douyin.com/goodlife/v1/shop/poi/query/";
String result = null;
if (StringUtil.isNotEmpty(tiktokCouponDto.getAccountId())) {
result = HttpRequest.post(url)
.contentType("application/json")
.header("access-token", accessToken)
.form("account_id", tiktokCouponDto.getAccountId())
.form("page", 1)
.form("size", 50)
.execute().body();
} else {
result = HttpRequest.post(url)
.contentType("application/json")
.header("access-token", accessToken)
.form("poi_id", tiktokCouponDto.getAccountId())
.form("page", 1)
.form("size", 50)
.execute().body();
}
JSONObject entries = new JSONObject(result);
JSONObject data = entries.getJSONObject("data");
if (!data.getStr("error_code").equals(ErrorCodeEnum.SUCCESS.getCode())) {
return data.getStr("description");
}
JSONArray pois = data.getJSONArray("pois");
Object o = pois.get(0);
JSONObject object = new JSONObject(o);
//门店信息
JSONObject poi = object.getJSONObject("poi");
//生活服务商家账户信息
JSONObject rootAccount = object.getJSONObject("root_account");
return pois;
}
public String obtain() { public String obtain() {
String o; String o;
o = redisUtil.get(ReceiptRdeisEnum.TIKTOK_CLIENT_TOKEN.getValue()); o = redisUtil.get(ReceiptRdeisEnum.TIKTOK_CLIENT_TOKEN.getValue());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment