1. 核销需要用到的信息
- appid
- appsecret
- 门店id
- 账户id
2. 贴具体代码了(Junit)
//获取 access_token,对这个很熟悉吧
@Test
public void auth() {
String uri = "https://open.douyin.com/oauth/client_token/";
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("client_key", appKey);
paramMap.put("client_secret", appSecret);
paramMap.put("grant_type", "client_credential");
String result= HttpUtil.post(uri, paramMap);
System.out.println(result);
//{"data":{"access_token":"clt.8805b6ccbaaec42c64a034knkOTaroUB1P4Y55s","captcha":"","desc_url":"","description":"","error_code":0,"expires_in":7200,"log_id":"202313F9"},"message":"success"}
}
/** author:157239486
* 输码校验 code 方式
*/
@Test
public void preCode() {
String uri = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/";
String result = HttpRequest.get(uri)
.contentType("application/json")
.header("access-token", accessToken)
.form("code", "XXX").execute().body();
System.out.println(result);
/**
author:157239486
* 输码校验 encrypted_data
*/
@Test
public void preEncrypted() {
String uri = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/";
//二维码扫描出来的短链
String tempUri = "https://v.douyin.com/XXXX/";
String res = HttpUtil.get(tempUri);
//获取objectId
String encryptedDataUri = ReUtil.getGroup0(Validator.URL, res);
String objectId = UrlBuilder.of(encryptedDataUri).getQuery().get("object_id").toString();
System.out.println(objectId);
String result = HttpRequest.get(uri)
.contentType("application/json")
.header("access-token", accessToken)
.form("encrypted_data", objectId).execute().body();
System.out.println(result);
}
/**
* 验券 valid
*/
@Test
public void valid() {
String uri = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/verify/";
JSONObject jsonObject = new JSONObject();
jsonObject.put("verify_token","xxx");
jsonObject.put("poi_id","xxx");
JSONArray encryptedCodeArray = new JSONArray();
encryptedCodeArray.add("xxx");
jsonObject.put("encrypted_codes",encryptedCodeArray);
System.out.println(jsonObject.toString());
String result = HttpRequest.post(uri)
.contentType("application/json")
.header("access-token", accessToken)
.body(jsonObject.toJSONString()).execute().body();
System.out.println(result);
}
6. 结语
具体使用就不用说了吧,单独做一个service,在需要使用的时候注入service,在业务中直接调用就行。
注意:java抖音核销要自行在代码中记录核销状态,如果你不停的调用同一个核销,它会一直返回成功,美团是不用的,美团当你第二次调用的时候就会提示不能使用了。