feat(backend): 添加集材社调用接口
- 新增 HomeController 类,实现集材社调用的接口 - 添加订单信息获取和更新功能 - 使用 Swagger 注解进行接口文档化 -集成幂等性注解防止重复提交
This commit is contained in:
@@ -15,32 +15,64 @@ import java.util.*;
|
||||
*/
|
||||
public class WxXcxUtils {
|
||||
|
||||
private static final String APPID = "wxf1d78a0b58fc890c";
|
||||
private static final String SECRET = "e1a3e888471d48addf1a23e4c9ea7f84";
|
||||
private static final String TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
|
||||
private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
private static final String APPID = "wxc4ed85cf2d8bdc63";
|
||||
private static final String SECRET = "787dcb857129514c4eae72501a3acb18";
|
||||
private static final String TICKET_URL = "https://api.weixin.qq.com";
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
*/
|
||||
public static String getAccessToken(){
|
||||
String url = TOKEN_URL + "?grant_type=client_credential&appid=" + APPID + "&secret=" + SECRET;
|
||||
String url = TICKET_URL + "/cgi-bin/token?grant_type=client_credential&appid=" + APPID + "&secret=" + SECRET;
|
||||
String result = HttpUtil.get(url);
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
return jsonObject.getString("access_token");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户手机号码
|
||||
*/
|
||||
public static JSONObject getUserPhoneNumber(String code){
|
||||
String accessToken = getAccessToken();
|
||||
String url = TICKET_URL + "/wxa/business/getuserphonenumber?access_token="+accessToken;
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", code);
|
||||
String result = HttpRequest.post(url).body(json.toString()).execute().body();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jsapi_ticket
|
||||
*/
|
||||
public static String getJsapiTicket() {
|
||||
String accessToken = getAccessToken();
|
||||
String url = TICKET_URL + "?access_token=" + accessToken + "&type=jsapi";
|
||||
String url = TICKET_URL + "/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi";
|
||||
String result = HttpUtil.get(url);
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
return jsonObject.getString("ticket");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小程序二维码
|
||||
* @param scene 场景值ID
|
||||
* @param page 页面路径
|
||||
* @param width 二维码宽度
|
||||
* @return 二维码图片的二进制数据
|
||||
*/
|
||||
public static byte[] getQrCode(String scene, String page, int width) {
|
||||
String accessToken = getAccessToken();
|
||||
String url = TICKET_URL + "/wxa/getwxacodeunlimit?access_token=" + accessToken;
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("scene", scene);
|
||||
json.put("page", page);
|
||||
json.put("width", width);
|
||||
String result = HttpRequest.post(url).body(json.toString()).execute().body();
|
||||
return result.getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名
|
||||
* @param url 当前网页的URL
|
||||
|
||||
Reference in New Issue
Block a user