Commit 8bf4a9dc authored by 王敬磊's avatar 王敬磊

添加token参数校验方法及示例

parent a0b30aaf
...@@ -14,8 +14,6 @@ import org.apache.http.util.EntityUtils; ...@@ -14,8 +14,6 @@ import org.apache.http.util.EntityUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/** /**
* 类描述: token生成及接口请求示例 * 类描述: token生成及接口请求示例
...@@ -43,42 +41,26 @@ public class GenerateTokenExample { ...@@ -43,42 +41,26 @@ public class GenerateTokenExample {
public static void main(String[] args) { public static void main(String[] args) {
String url = "https://openapi.qmai.co/v3/baking/customer/userRecharge"; String url = "https://openapi.qmai.co/v3/baking/customer/userRecharge";
String token = QmaiTokenUtil.getToken(grantCode, openId, openKey, nonce, timestamp); String token = QmaiTokenUtil.getToken(grantCode, openId, openKey, nonce, timestamp);
BaseOuterOpenapiRequest<JSONObject> request = new BaseOuterOpenapiRequest<>(); BaseOuterOpenapiRequest<JSONObject> request = new BaseOuterOpenapiRequest<>();
request.setNonce(nonce);
request.setToken(token);
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("openId", openId); request.setToken(token);
requestParam.put("grantCode", grantCode); request.setNonce(nonce);
request.setOpenId(openId);
request.setGrantCode(grantCode);
request.setTimestamp(timestamp);
// 业务参数 content // 业务参数 content
HashMap<String, Object> bizParam = new HashMap<>(); JSONObject bizParam = new JSONObject();
bizParam.put("shopCode", 18); request.setParams(bizParam);
bizParam.put("activityId", "785425500976746497");
bizParam.put("amount", 300); String response = doPost(url, request);
bizParam.put("giveAmount", 20);
bizParam.put("bizId", "2102819060916404224");
bizParam.put("source", "8");
HashMap<String, Object> customerCodeType = new HashMap<>();
customerCodeType.put("customerCode", "778770795093545867");
customerCodeType.put("type", "9");
bizParam.put("customerCodeType", customerCodeType);
bizParam.put("remarks", "");
requestParam.put("params", bizParam);
requestParam.put("nonce", nonce);
requestParam.put("timestamp", timestamp);
requestParam.put("token", token);
String response = doPost(url, requestParam);
System.out.println(response); System.out.println(response);
} }
public static String doPost(String url, Map<String, Object> param) { public static String doPost(String url, BaseOuterOpenapiRequest<JSONObject> param) {
CloseableHttpClient httpClient = HttpClientBuilder.create().build(); CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try { try {
if (httpClient == null) { if (httpClient == null) {
......
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