|
|
|
|
@ -34,7 +34,7 @@ public class WxPayUtils { |
|
|
|
|
|
|
|
|
|
//微信下单回调地址,支付成功后会回调这个地址。
|
|
|
|
|
//对应文档 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_5.shtml
|
|
|
|
|
public static String callbackUri = ""; |
|
|
|
|
public static String callbackUri = "https://www.baidu.com"; |
|
|
|
|
|
|
|
|
|
//APIv3密钥 在微信支付商户平台-账户中心-API安全里设置,如果设置了不知道,就只有修改
|
|
|
|
|
public static String apiV3Key = "YLJJyilvjiaju3613369520230822YLJ"; |
|
|
|
|
@ -122,12 +122,12 @@ public class WxPayUtils { |
|
|
|
|
* 官方文档路径 |
|
|
|
|
* https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter2_1.shtml
|
|
|
|
|
*/ |
|
|
|
|
public static String createOrderJSApiV3(String openId, String outTradeNo) { |
|
|
|
|
public static String createOrderJSApiV3(String openId, String outTradeNo,int total) { |
|
|
|
|
payLoading(); |
|
|
|
|
//请求URL
|
|
|
|
|
HttpPost httpPost = new HttpPost(JSApiPayUrl); |
|
|
|
|
// 请求body参数
|
|
|
|
|
StringEntity entity = new StringEntity(JSONObject.toJSONString(buildWxJsApiV3PayJson(openId, outTradeNo, 0)), "utf-8"); |
|
|
|
|
StringEntity entity = new StringEntity(JSONObject.toJSONString(buildWxJsApiV3PayJson(openId, outTradeNo, total)), "utf-8"); |
|
|
|
|
entity.setContentType("application/json"); |
|
|
|
|
httpPost.setEntity(entity); |
|
|
|
|
httpPost.setHeader("Accept", "application/json"); |
|
|
|
|
@ -196,8 +196,8 @@ public class WxPayUtils { |
|
|
|
|
* @param openId openId |
|
|
|
|
* @return 支付参数 |
|
|
|
|
*/ |
|
|
|
|
public static Object getPayParam(String openId, String outTradeNo) { |
|
|
|
|
JSONObject jsonObject = JSON.parseObject(createOrderJSApiV3(openId, outTradeNo)); |
|
|
|
|
public static Object getPayParam(String openId, String outTradeNo,int total) { |
|
|
|
|
JSONObject jsonObject = JSON.parseObject(createOrderJSApiV3(openId, outTradeNo,total)); |
|
|
|
|
return getTokenWeiXin(jsonObject.getString("prepay_id")); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -207,14 +207,14 @@ public class WxPayUtils { |
|
|
|
|
* 构造下单的json(第三步需要) |
|
|
|
|
* |
|
|
|
|
* @param description 商品描述 |
|
|
|
|
* @param amount 订单金额 |
|
|
|
|
* @param total 订单金额 |
|
|
|
|
* @param openId 用户ID onAky51Fojn3NoLrnKwcY |
|
|
|
|
* @return JSONObject |
|
|
|
|
*/ |
|
|
|
|
public static JSONObject buildWxJsApiV3PayJson(String description, String amount, String openId, String outTradeNo) { |
|
|
|
|
public static JSONObject buildWxJsApiV3PayJson(String description, int total, String openId, String outTradeNo) { |
|
|
|
|
//订单金额json
|
|
|
|
|
JSONObject amountJson = new JSONObject(); |
|
|
|
|
amountJson.put("total", Integer.valueOf(amount)); |
|
|
|
|
amountJson.put("total", total); |
|
|
|
|
amountJson.put("currency", "CNY"); |
|
|
|
|
|
|
|
|
|
//支付者json
|
|
|
|
|
@ -242,8 +242,8 @@ public class WxPayUtils { |
|
|
|
|
* |
|
|
|
|
* @return JSONObject |
|
|
|
|
*/ |
|
|
|
|
public static JSONObject buildWxJsApiV3PayJson(String openId, String outTradeNo, Integer goodsId) { |
|
|
|
|
return buildWxJsApiV3PayJson("测试商品", "1", openId, outTradeNo); |
|
|
|
|
public static JSONObject buildWxJsApiV3PayJson(String openId, String outTradeNo, int total) { |
|
|
|
|
return buildWxJsApiV3PayJson("测试商品", total, openId, outTradeNo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -252,7 +252,7 @@ public class WxPayUtils { |
|
|
|
|
* @return JSONObject |
|
|
|
|
*/ |
|
|
|
|
public static JSONObject buildWxJsApiV3PayJson() { |
|
|
|
|
return buildWxJsApiV3PayJson("测试商品", "1", "123123123124", ""); |
|
|
|
|
return buildWxJsApiV3PayJson("测试商品", 1, "123123123124", ""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|