公众号支付 + 回调解析 + 配置文件补充
This commit is contained in:
parent
9956a2bd7d
commit
4cb7e800ec
|
|
@ -6,18 +6,22 @@ import com.ghy.common.adapay.callback.model.WxLiteExpend;
|
||||||
import com.ghy.common.adapay.callback.reply.WxPubPayCallBack;
|
import com.ghy.common.adapay.callback.reply.WxPubPayCallBack;
|
||||||
import com.ghy.common.core.controller.BaseController;
|
import com.ghy.common.core.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.common.utils.ExceptionUtil;
|
||||||
import com.ghy.common.utils.WxUtils;
|
import com.ghy.common.utils.WxUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/pay/wx")
|
@RequestMapping("/pay/wx")
|
||||||
public class WxPayController extends BaseController {
|
public class WxPayController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private AdapayService adapayService;
|
private AdapayService adapayService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,21 +36,27 @@ public class WxPayController extends BaseController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult pubPay(HttpServletRequest request){
|
public AjaxResult pubPay(HttpServletRequest request){
|
||||||
String code = request.getParameter("code");
|
String code = request.getParameter("code");
|
||||||
|
logger.info("code is " + code);
|
||||||
//测试时前端不带订单号.
|
//测试时前端不带订单号.
|
||||||
// String orderId = request.getParameter("orderId");
|
// String orderId = request.getParameter("orderId");
|
||||||
// 查询回订单信息。如果订单不存在,则退出.
|
// 查询回订单信息。如果订单不存在,则退出.
|
||||||
try {
|
try {
|
||||||
JSONObject wxUser = WxUtils.getOpenid(code);
|
JSONObject wxUser = WxUtils.getOpenid(code);
|
||||||
String openId = wxUser.getString("openid");
|
String openId = wxUser.getString("openid");
|
||||||
|
logger.info("open id is " + openId);
|
||||||
//调用adapay微信公众号支付.
|
//调用adapay微信公众号支付.
|
||||||
WxLiteExpend expend = new WxLiteExpend();
|
WxLiteExpend expend = new WxLiteExpend();
|
||||||
expend.setOpen_id(openId);
|
expend.setOpen_id(openId);
|
||||||
adapayService.wxPubPay(new WxPubPayCallBack(), expend, "wxPay123456" + Math.ceil(Math.random()*100), "1.00",
|
Map<String, Object> map = adapayService.wxPubPay(new WxPubPayCallBack(), expend, "wxPay123456" + Math.ceil(Math.random()*100), "1.00",
|
||||||
"测试商品", "测试商品detail", "description");
|
"测试商品", "测试商品detail", "description");
|
||||||
//拼接消息给前端.前端通过JSAPI调用微信支付
|
//拼接消息给前端.前端通过JSAPI调用微信支付
|
||||||
|
map.forEach((key,value)->{
|
||||||
|
logger.info("key is " + key + ", value is " + value);
|
||||||
|
});
|
||||||
|
return AjaxResult.success(map);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error(e.getMessage());
|
logger.error(ExceptionUtil.getExceptionMessage(e));
|
||||||
}
|
}
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,4 +152,4 @@ adapay:
|
||||||
notifyUrl: 'http://www.opsoul.com/adapay/callback'
|
notifyUrl: 'http://www.opsoul.com/adapay/callback'
|
||||||
apiKey: 'api_live_93a2fb4f-a74a-416f-967d-68557bcde43f'
|
apiKey: 'api_live_93a2fb4f-a74a-416f-967d-68557bcde43f'
|
||||||
mockApiKey: 'api_test_88bf2958-583d-41cd-a987-01fe767ff056'
|
mockApiKey: 'api_test_88bf2958-583d-41cd-a987-01fe767ff056'
|
||||||
rsaPrivateKey: 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxcoRizdqBD3pEYVlJg/BkmNoHA2T/craoCKKh2rjBo3GKmuug6mHi+gesxtiGe6arcNU7Yv20rSySHw/rKpp7pNHivLrV4lHWjIVfV/2OCTpPzAbEoWr2nfx9UhQxru5Jue/fsO6VjPv27sFMXJ8pRmqok+eRDUqjuEEKr74oQwIDAQAB'
|
rsaPrivateKey: 'MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMTk5xzz3KXA+waawr1DbU/SaSXZN8tY/22qHON7AAsp+yJ1/JCt+sD6/mpIUGittBS4n69t/9R5+2uHtD5/tVH7hYpJpVixLQw8/lonLPbeLFLgTMBHKJwSytBZXC2delnewHO/Zg6WlTWkdQB7gr73m7/wu2Ss+FDwGq6Q8sXdAgMBAAECgYEAtl8LTr72DjWsjdaFMEcnFftf12XWjyx1Ev+xWGcSiESvT6EXem8bxun1Az7N89eI6HSFvDlX8Fe4MEZ3BjjGGXSEXh3BYg5jI9YY/x4NdPvCxxVf9gGmBo2uBjkPoqYE8IGfpxnF+C4CBEyI5FPjhQRYB7aPKL7hImoCFkaFG4UCQQDojfLHd2ON2sgZdeAML9jxNzf1CBsGVfDrI7GOj+enWG+lWjG5tav/essfDOlZ6rZslyquLQZAGQqZz06cVCMzAkEA2L6WuCiEop9gsnGk03UcO8u54jFC68+2IA4bJeqicFmqMgs73PzsnNZ7t31q51iGsKxvCm3hziTGHGGH9TZyrwJATda1XG5ptCF2uI7r3yhkxNhmsm10HjrF2O6pj747G5hORlpaKn7Ugz7mng4ETURyqwYuEv6fCPVYxwLMnSbMYQJBAMggMkoYH1+IiWA6TlZw64DKuvd/RKs3PpKac7auzw2tvNg4Ry3k2xR1dgYWZ3703miCzoRysOwGSGYsJ7ziaUECQQC1RqZ0UBtEbKSr9fRYxo/lg28ioTlxoMjSL2OumEyJk+2t0S3gPQq5Wz+ylcwnK3Md0kGTyYs5kkTWPyPm9V1F'
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import org.springframework.util.Assert;
|
||||||
* @author HH 2022/3/25
|
* @author HH 2022/3/25
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty("adapay")
|
|
||||||
@EnableConfigurationProperties(AdapayProperties.class)
|
@EnableConfigurationProperties(AdapayProperties.class)
|
||||||
public class AdapayAutoConfiguration {
|
public class AdapayAutoConfiguration {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@ import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
import com.huifu.adapay.model.Drawcash;
|
import com.huifu.adapay.model.Drawcash;
|
||||||
import com.huifu.adapay.model.Payment;
|
import com.huifu.adapay.model.Payment;
|
||||||
import com.huifu.adapay.model.Refund;
|
import com.huifu.adapay.model.Refund;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.Setter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -21,10 +24,13 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* @author HH 2022/3/25
|
* @author HH 2022/3/25
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Setter
|
||||||
public class AdapayService {
|
public class AdapayService {
|
||||||
|
|
||||||
AdapayProperties adapayProperties;
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdapayProperties adapayProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对指定商户或者商户下用户的结算账户可用余额发起主动取现操作,金额从账户中提到绑定的结算银行卡中
|
* 对指定商户或者商户下用户的结算账户可用余额发起主动取现操作,金额从账户中提到绑定的结算银行卡中
|
||||||
|
|
@ -95,12 +101,6 @@ public class AdapayService {
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> pay(PayCallback callback, String payChannel, Expend expend, String orderNo, String payAmt,
|
public Map<String, Object> pay(PayCallback callback, String payChannel, Expend expend, String orderNo, String payAmt,
|
||||||
String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
|
String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
|
||||||
Assert.notNull(callback, "callback is null!");
|
|
||||||
Assert.hasText(orderNo, "orderNo is blank!");
|
|
||||||
Assert.hasText(payAmt, "payAmt is blank!");
|
|
||||||
Assert.hasText(goodsTittle, "goodsTittle is blank!");
|
|
||||||
Assert.hasText(goodsDesc, "goodsDesc is blank!");
|
|
||||||
Assert.hasText(payChannel, "payChannel is blank!");
|
|
||||||
Map<String, Object> paymentParams = new HashMap<>(16);
|
Map<String, Object> paymentParams = new HashMap<>(16);
|
||||||
paymentParams.put("app_id", adapayProperties.getAppId());
|
paymentParams.put("app_id", adapayProperties.getAppId());
|
||||||
paymentParams.put("notify_url", adapayProperties.getNotifyUrl());
|
paymentParams.put("notify_url", adapayProperties.getNotifyUrl());
|
||||||
|
|
@ -112,6 +112,10 @@ public class AdapayService {
|
||||||
paymentParams.put("description", description);
|
paymentParams.put("description", description);
|
||||||
paymentParams.put("expend", expend);
|
paymentParams.put("expend", expend);
|
||||||
PayReplyMapping.putCallback(orderNo, callback);
|
PayReplyMapping.putCallback(orderNo, callback);
|
||||||
|
|
||||||
|
paymentParams.forEach((key,value)->{
|
||||||
|
logger.info("key is " + key + ", value is " + value);
|
||||||
|
});
|
||||||
return Payment.create(paymentParams);
|
return Payment.create(paymentParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ import com.ghy.common.adapay.callback.mapping.PayReplyMapping;
|
||||||
import com.ghy.common.adapay.callback.mapping.RefundReplyMapping;
|
import com.ghy.common.adapay.callback.mapping.RefundReplyMapping;
|
||||||
import com.huifu.adapay.core.AdapayCore;
|
import com.huifu.adapay.core.AdapayCore;
|
||||||
import com.huifu.adapay.core.util.AdapaySign;
|
import com.huifu.adapay.core.util.AdapaySign;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
@ -17,21 +18,24 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
*
|
*
|
||||||
* @author HH 2022/3/25
|
* @author HH 2022/3/25
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@RestController
|
@RestController
|
||||||
public class AdapayCallbackController {
|
public class AdapayCallbackController {
|
||||||
|
|
||||||
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
@PostMapping("/adapay/callback")
|
@PostMapping("/adapay/callback")
|
||||||
public String callback(@RequestBody Event event) {
|
public String callback(@RequestBody Event event) {
|
||||||
|
logger.info(" 收单返回消息event" + event);
|
||||||
//验签请参data
|
//验签请参data
|
||||||
String data = event.getData();
|
String data = event.getData();
|
||||||
|
logger.info(" 收单返回消息data" + data);
|
||||||
//验签请参sign
|
//验签请参sign
|
||||||
String sign = event.getSign();
|
String sign = event.getSign();
|
||||||
boolean verifySign = false;
|
boolean verifySign = false;
|
||||||
try {
|
try {
|
||||||
verifySign = verifySign(data, sign);
|
verifySign = verifySign(data, sign);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("签名验证失败 {}", e.getMessage());
|
logger.error("签名验证失败 {}", e.getMessage());
|
||||||
}
|
}
|
||||||
if (verifySign) {
|
if (verifySign) {
|
||||||
//Event事件类型
|
//Event事件类型
|
||||||
|
|
@ -53,12 +57,12 @@ public class AdapayCallbackController {
|
||||||
DrawCashReplyMapping.putReply(event);
|
DrawCashReplyMapping.putReply(event);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.warn("UNKNOWN EVENT TYPE [{}]", type);
|
logger.warn("UNKNOWN EVENT TYPE [{}]", type);
|
||||||
return "NG";
|
return "NG";
|
||||||
}
|
}
|
||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
log.warn("签名验证失败 data=[{}], sign=[{}]", data, sign);
|
logger.warn("签名验证失败 data=[{}], sign=[{}]", data, sign);
|
||||||
return "NG";
|
return "NG";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +78,7 @@ public class AdapayCallbackController {
|
||||||
Assert.hasText(sign, "sign is blank!");
|
Assert.hasText(sign, "sign is blank!");
|
||||||
//验签请参publicKey
|
//验签请参publicKey
|
||||||
String publicKey = AdapayCore.PUBLIC_KEY;
|
String publicKey = AdapayCore.PUBLIC_KEY;
|
||||||
log.debug("验签请参:data={}sign={}", data, sign);
|
logger.debug("验签请参:data={}sign={}", data, sign);
|
||||||
//验签
|
//验签
|
||||||
return AdapaySign.verifySign(data, sign, publicKey);
|
return AdapaySign.verifySign(data, sign, publicKey);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,7 @@ public class ShiroConfig
|
||||||
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||||
//部分接口不需要登陆校验
|
//部分接口不需要登陆校验
|
||||||
filterChainDefinitionMap.put("/wx/**", "anon");
|
filterChainDefinitionMap.put("/wx/**", "anon");
|
||||||
|
filterChainDefinitionMap.put("/pay/**", "anon");
|
||||||
filterChainDefinitionMap.put("/adapay/**", "anon");
|
filterChainDefinitionMap.put("/adapay/**", "anon");
|
||||||
filterChainDefinitionMap.put("/MP_verify_bRFuvYpyQ4WLr0on.txt", "anon");
|
filterChainDefinitionMap.put("/MP_verify_bRFuvYpyQ4WLr0on.txt", "anon");
|
||||||
// 对静态资源设置匿名访问
|
// 对静态资源设置匿名访问
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue