Commit 987ca904 authored by cy's avatar cy

微信支付

parent dc3bab05
...@@ -80,8 +80,7 @@ public class AliPayServiceImpl implements AliPayService { ...@@ -80,8 +80,7 @@ public class AliPayServiceImpl implements AliPayService {
alipayRequest.setReturnUrl(Common.RETURN_URL_PC); alipayRequest.setReturnUrl(Common.RETURN_URL_PC);
//支付回调地址 //支付回调地址
alipayRequest.setNotifyUrl(Common.NOTIFY_URL); alipayRequest.setNotifyUrl(Common.NOTIFY_URL);
//alipayRequest.setNotifyUrl(" http://tcdwak.natappfree.cc/pay/aliPayCallBack.do"); //alipayRequest.setNotifyUrl(" http://iub3mv.natappfree.cc/pay/aliPayCallBack.do");
alipayRequest.setBizContent("{" + alipayRequest.setBizContent("{" +
"\"out_trade_no\":\"" + tradeNo + "\"," + "\"out_trade_no\":\"" + tradeNo + "\"," +
"\"total_amount\":" + amount + "," + "\"total_amount\":" + amount + "," +
......
...@@ -61,12 +61,15 @@ public class TestWxPayServiceImpl implements TestWxPayService { ...@@ -61,12 +61,15 @@ public class TestWxPayServiceImpl implements TestWxPayService {
System.out.println(orderInfo); System.out.println(orderInfo);
//调用统一下单接口 //调用统一下单接口
Map<String, String> map = unifiedOrder(orderInfo); Map<String, String> map = unifiedOrder(orderInfo);
String return_msg = map.get("return_msg");//返回信息 //返回信息
String return_code = map.get("return_code");//状态码 String return_msg = map.get("return_msg");
String result_code = map.get("result_code");//业务结果 //状态码
String return_code = map.get("return_code");
//业务结果
String result_code = map.get("result_code");
String code_url = map.get("code_url"); String code_url = map.get("code_url");
System.out.println("return_msg:"+return_msg); System.out.println("return_msg:"+return_msg);
System.out.println("return_code:"+return_code);
log.info("支付返回信息:"+return_msg,return_code); log.info("支付返回信息:"+return_msg,return_code);
if (null != map && "SUCCESS".equals(return_code) && "SUCCESS".equals(result_code)) { if (null != map && "SUCCESS".equals(return_code) && "SUCCESS".equals(result_code)) {
PayRecord payRecord = new PayRecord(); PayRecord payRecord = new PayRecord();
...@@ -109,9 +112,12 @@ public class TestWxPayServiceImpl implements TestWxPayService { ...@@ -109,9 +112,12 @@ public class TestWxPayServiceImpl implements TestWxPayService {
System.out.println(orderInfo); System.out.println(orderInfo);
//调用统一下单接口 //调用统一下单接口
Map<String, String> map = unifiedOrder(orderInfo); Map<String, String> map = unifiedOrder(orderInfo);
String return_msg = map.get("return_msg");//返回信息 //返回信息
String return_code = map.get("return_code");//状态码 String return_msg = map.get("return_msg");
String result_code = map.get("result_code");//业务结果 //状态码
String return_code = map.get("return_code");
//业务结果
String result_code = map.get("result_code");
String urlString = URLEncoder.encode("http://www.baidu.com", "GBK"); String urlString = URLEncoder.encode("http://www.baidu.com", "GBK");
String mweb_url = map.get("mweb_url")+"&redirect_url="+urlString; String mweb_url = map.get("mweb_url")+"&redirect_url="+urlString;
log.info("支付返回信息:",return_msg,"状态码:",return_code); log.info("支付返回信息:",return_msg,"状态码:",return_code);
...@@ -159,7 +165,7 @@ public class TestWxPayServiceImpl implements TestWxPayService { ...@@ -159,7 +165,7 @@ public class TestWxPayServiceImpl implements TestWxPayService {
String return_code = map.get("return_code");//状态码 String return_code = map.get("return_code");//状态码
String result_code = map.get("result_code");//业务结果 String result_code = map.get("result_code");//业务结果
log.info("支付返回信息:",return_msg,"状态码:",return_code); log.info("支付返回信息:",return_msg);
if (null != map && "SUCCESS".equals(return_code) && "SUCCESS".equals(result_code)) { if (null != map && "SUCCESS".equals(return_code) && "SUCCESS".equals(result_code)) {
PayRecord payRecord = new PayRecord(); PayRecord payRecord = new PayRecord();
payRecord.setMoney(payPageDto.getTotal()); payRecord.setMoney(payPageDto.getTotal());
...@@ -171,17 +177,17 @@ public class TestWxPayServiceImpl implements TestWxPayService { ...@@ -171,17 +177,17 @@ public class TestWxPayServiceImpl implements TestWxPayService {
SortedMap<String,String> mapParams = new TreeMap<String,String>(); SortedMap<String,String> mapParams = new TreeMap<String,String>();
mapParams.put("return_code", return_code); mapParams.put("return_code", return_code);
mapParams.put("return_msg", return_msg); mapParams.put("return_msg", return_msg);
String prepay_id = map.get("prepay_id");//返回的预付单信息 小程序端使用 //返回的预付单信息 小程序端使用
String prepay_id = map.get("prepay_id");
mapParams.put("nonceStr", nonce_str); mapParams.put("nonceStr", nonce_str);
mapParams.put("package", "prepay_id=" + prepay_id); mapParams.put("package", "prepay_id=" + prepay_id);
Long timeStamp = new Date().getTime(); Long timeStamp = new Date().getTime();
mapParams.put("timeStamp", timeStamp + "");//这边要将返回的时间戳转化成字符串,不然小程序端调用wx.requestPayment方法会报签名错误 //这边要将返回的时间戳转化成字符串,不然小程序端调用wx.requestPayment方法会报签名错误
mapParams.put("timeStamp", timeStamp + "");
String characterEncoding = "UTF-8"; String characterEncoding = "UTF-8";
String paySign=WxPayUtil.createSign(characterEncoding,mapParams); String paySign=WxPayUtil.createSign(characterEncoding,mapParams);
mapParams.put("paySign", paySign); mapParams.put("paySign", paySign);
mapParams.put("appid", ""); mapParams.put("appid", "");
} }
System.out.println("mweb_url:"); System.out.println("mweb_url:");
return R.ok("0"); return R.ok("0");
......
...@@ -164,8 +164,10 @@ public class VolunteerManager { ...@@ -164,8 +164,10 @@ public class VolunteerManager {
PayRecord byTradeNo = payRecordMapper.selectOne(queryWrapper); PayRecord byTradeNo = payRecordMapper.selectOne(queryWrapper);
int pay; int pay;
if (null != byTradeNo) { if (null != byTradeNo) {
payRecord.setId(byTradeNo.getId());
pay = payRecordMapper.updateById(payRecord); pay = payRecordMapper.updateById(payRecord);
} else { } else {
pay = payRecordMapper.add(payRecord); pay = payRecordMapper.add(payRecord);
} }
return pay != 0; return pay != 0;
......
...@@ -191,15 +191,17 @@ public class WxPayUtil { ...@@ -191,15 +191,17 @@ public class WxPayUtil {
String nonce_str = RandomStringUtils.randomAlphanumeric(16); String nonce_str = RandomStringUtils.randomAlphanumeric(16);
SortedMap<String,String> parameters = new TreeMap<String,String>(); SortedMap<String,String> parameters = new TreeMap<String,String>();
parameters.put("appid", WxCommon.APP_ID); parameters.put("appid", WxCommon.APP_ID);
parameters.put("mchid", mchId); parameters.put("mch_id",mchId);
parameters.put("body", "充值"); parameters.put("body", "充值");
parameters.put("description","充值");
parameters.put("out_trade_no", tradeNo); parameters.put("out_trade_no", tradeNo);
parameters.put("nonce_str", nonce_str); parameters.put("notify_url",WxCommon.NOTIFY_URL);
DecimalFormat df = new DecimalFormat("#"); DecimalFormat df = new DecimalFormat("#");
//parameters.put("total_fee", df.format(payPageDto.getTotal()*100)); //parameters.put("total_fee", df.format(payPageDto.getTotal()*100));
parameters.put("total_fee", df.format(1)); parameters.put("total_fee", df.format(1));
parameters.put("notify_url",WxCommon.NOTIFY_URL); parameters.put("nonce_str", nonce_str);
parameters.put("trade_type","NATIVE"); parameters.put("trade_type","NATIVE");
parameters.put("product_id", "100001");
String characterEncoding = "UTF-8"; String characterEncoding = "UTF-8";
String sign = createSign(characterEncoding,parameters); String sign = createSign(characterEncoding,parameters);
parameters.put("sign", sign);//签名 parameters.put("sign", sign);//签名
...@@ -261,12 +263,14 @@ public class WxPayUtil { ...@@ -261,12 +263,14 @@ public class WxPayUtil {
parameters.put("appid", appid); parameters.put("appid", appid);
parameters.put("mchid", mchid); parameters.put("mchid", mchid);
parameters.put("body", "充值"); parameters.put("body", "充值");
parameters.put("description","充值");
parameters.put("out_trade_no", tradeNo); parameters.put("out_trade_no", tradeNo);
parameters.put("notify_url",WxCommon.NOTIFY_URL);
parameters.put("nonce_str", nonce_str); parameters.put("nonce_str", nonce_str);
DecimalFormat df = new DecimalFormat("#"); DecimalFormat df = new DecimalFormat("#");
//parameters.put("total_fee", df.format(payPageDto.getTotal()*100)); //parameters.put("total_fee", df.format(payPageDto.getTotal()*100));
parameters.put("total_fee", df.format(1)); parameters.put("total_fee", df.format(1));
parameters.put("notify_url",WxCommon.NOTIFY_URL);
parameters.put("trade_type","JSAPI"); parameters.put("trade_type","JSAPI");
String characterEncoding = "UTF-8"; String characterEncoding = "UTF-8";
String sign = createSign(characterEncoding,parameters); String sign = createSign(characterEncoding,parameters);
......
...@@ -56,7 +56,7 @@ public class PayController { ...@@ -56,7 +56,7 @@ public class PayController {
@ApiImplicitParam(name = "payPageDto", value = "参数", dataType = "PayPageDto") @ApiImplicitParam(name = "payPageDto", value = "参数", dataType = "PayPageDto")
@PostMapping("/page") @PostMapping("/page")
public R<String> doPost(@RequestBody PayPageDto payPageDto, HttpServletRequest request, HttpServletResponse httpResponse) { public R<String> doPost(@RequestBody PayPageDto payPageDto, HttpServletRequest request, HttpServletResponse httpResponse) {
/*public R<String> doPost(Integer userId,Integer payType,Integer total_amount, HttpServletRequest request, HttpServletResponse httpResponse) { /* public R<String> doPost(Integer userId,Integer payType,Integer total_amount, HttpServletRequest request, HttpServletResponse httpResponse) {
PayPageDto payPageDto = new PayPageDto(); PayPageDto payPageDto = new PayPageDto();
payPageDto.setTotal(total_amount); payPageDto.setTotal(total_amount);
payPageDto.setUserId(userId); payPageDto.setUserId(userId);
......
...@@ -3,8 +3,8 @@ spring: ...@@ -3,8 +3,8 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
druid: druid:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
#url: jdbc:mysql://192.168.110.165:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8 url: jdbc:mysql://192.168.110.165:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
url: jdbc:mysql://localhost:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8 #url: jdbc:mysql://localhost:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
username: root username: root
password: adm4HYservice$ password: adm4HYservice$
initial-size: 10 initial-size: 10
......
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