# Conflicts:
#	nursing-unit-admin/nu-admin-biz/src/main/java/com/nu/modules/wechart/controller/WechatPayController.java
This commit is contained in:
1378012178@qq.com 2025-06-19 15:07:25 +08:00
commit d4d164ecbb
5 changed files with 23 additions and 5 deletions

View File

@ -315,7 +315,6 @@ public class WechatPayController {
@PostMapping("/getUserInfo") @PostMapping("/getUserInfo")
public JSONObject getWxUserInfo(@RequestBody Map<String, String> params) throws Exception { public JSONObject getWxUserInfo(@RequestBody Map<String, String> params) throws Exception {
// String accessToken = getToken(GET_TOKEN_URL, "wx8fc3e4305d2fbf0b", "3bf3dd4ec72f591432db6b28c2c044e5");// 获取token
String accessToken = params.get("access_token"); String accessToken = params.get("access_token");
String openid = params.get("openid"); String openid = params.get("openid");
System.out.println("---------token-------" + accessToken); System.out.println("---------token-------" + accessToken);
@ -341,9 +340,10 @@ public class WechatPayController {
@PostMapping("/getJsApiInfo") @PostMapping("/getJsApiInfo")
public static Map<String, String> getJsApiInfo(@RequestBody Map<String, String> params) throws Exception { public Map<String,String> getJsApiInfo(@RequestBody Map<String,String> params) throws Exception {
// String accessToken = getToken(GET_TOKEN_URL, "wx8fc3e4305d2fbf0b", "3bf3dd4ec72f591432db6b28c2c044e5");// 获取token String accessToken = getToken(GET_TOKEN_URL, wechatpayConfig.getAppid(), wechatpayConfig.getAppsecret());// 获取token
String accessToken = params.get("access_token"); String firstUrl = params.get("url");
System.out.println("---------firstUrl-------"+firstUrl);
System.out.println("---------token-------" + accessToken); System.out.println("---------token-------" + accessToken);
// 构造请求URL // 构造请求URL
String requestUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi"; String requestUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi";
@ -364,13 +364,21 @@ public class WechatPayController {
String ticket = String.valueOf(jsonObject.get("ticket")); String ticket = String.valueOf(jsonObject.get("ticket"));
String nonceStr = UUID.randomUUID().toString(); String nonceStr = UUID.randomUUID().toString();
String timestamp = Long.toString(System.currentTimeMillis() / 1000); String timestamp = Long.toString(System.currentTimeMillis() / 1000);
String string1 = new StringBuilder("jsapi_ticket=").append(ticket).append("&noncestr=").append(nonceStr).append("&timestamp=").append(timestamp).toString();// 得到签名 String string1 = new StringBuilder("jsapi_ticket=").append(ticket)
.append("&noncestr=")
.append(nonceStr)
.append("&timestamp=")
.append(timestamp)
.append("&url=")
.append(firstUrl)
.toString();// 得到签名
String signature = encryptSHA(string1); String signature = encryptSHA(string1);
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("signature", signature); map.put("signature", signature);
map.put("timestamp", timestamp); map.put("timestamp", timestamp);
map.put("nonceStr", nonceStr); map.put("nonceStr", nonceStr);
map.put("firstUrl", firstUrl);
System.out.println("---------jsonObject-------" + signature); System.out.println("---------jsonObject-------" + signature);
return map; return map;

View File

@ -33,6 +33,10 @@ public class WechatpayConfig {
@Value("${wxpay.notify-domain}") @Value("${wxpay.notify-domain}")
private String notifyDomain; private String notifyDomain;
// APPID
@Value("${wxpay.appsecret}")
private String appsecret;
} }

View File

@ -395,6 +395,8 @@ wxpay:
api-v3-key: asdfiuzwe3534565478WETDSAFRWEq1E api-v3-key: asdfiuzwe3534565478WETDSAFRWEq1E
# APPID # APPID
appid: wx8fc3e4305d2fbf0b appid: wx8fc3e4305d2fbf0b
# appsecret
appsecret: 3bf3dd4ec72f591432db6b28c2c044e5
# 商户ID # 商户ID
mch-id: 1717618860 mch-id: 1717618860
# 商户API证书序列号 # 商户API证书序列号

View File

@ -391,6 +391,8 @@ wxpay:
api-v3-key: asdfiuzwe3534565478WETDSAFRWEq1E api-v3-key: asdfiuzwe3534565478WETDSAFRWEq1E
# APPID # APPID
appid: wx8fc3e4305d2fbf0b appid: wx8fc3e4305d2fbf0b
# appsecret
appsecret: 3bf3dd4ec72f591432db6b28c2c044e5
# 商户ID # 商户ID
mch-id: 1717618860 mch-id: 1717618860
# 商户API证书序列号 # 商户API证书序列号

View File

@ -389,6 +389,8 @@ wxpay:
api-v3-key: asdfiuzwe3534565478WETDSAFRWEq1E api-v3-key: asdfiuzwe3534565478WETDSAFRWEq1E
# APPID # APPID
appid: wx8fc3e4305d2fbf0b appid: wx8fc3e4305d2fbf0b
# appsecret
appsecret: 3bf3dd4ec72f591432db6b28c2c044e5
# 商户ID # 商户ID
mch-id: 1717618860 mch-id: 1717618860
# 商户API证书序列号 # 商户API证书序列号