公众号支付 + 回调解析 + 配置文件补充

This commit is contained in:
clunt 2022-04-12 10:06:42 +08:00
parent 9956a2bd7d
commit 4cb7e800ec
6 changed files with 37 additions and 19 deletions

View File

@ -6,18 +6,22 @@ import com.ghy.common.adapay.callback.model.WxLiteExpend;
import com.ghy.common.adapay.callback.reply.WxPubPayCallBack;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.WxUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Controller
@RequestMapping("/pay/wx")
public class WxPayController extends BaseController {
@Autowired
private AdapayService adapayService;
/**
@ -32,21 +36,27 @@ public class WxPayController extends BaseController {
@ResponseBody
public AjaxResult pubPay(HttpServletRequest request){
String code = request.getParameter("code");
logger.info("code is " + code);
//测试时前端不带订单号.
// String orderId = request.getParameter("orderId");
// 查询回订单信息如果订单不存在则退出.
try {
JSONObject wxUser = WxUtils.getOpenid(code);
String openId = wxUser.getString("openid");
logger.info("open id is " + openId);
//调用adapay微信公众号支付.
WxLiteExpend expend = new WxLiteExpend();
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");
//拼接消息给前端.前端通过JSAPI调用微信支付
map.forEach((key,value)->{
logger.info("key is " + key + ", value is " + value);
});
return AjaxResult.success(map);
}catch (Exception e){
e.printStackTrace();
logger.error(e.getMessage());
logger.error(ExceptionUtil.getExceptionMessage(e));
}
return AjaxResult.success();
}

View File

@ -152,4 +152,4 @@ adapay:
notifyUrl: 'http://www.opsoul.com/adapay/callback'
apiKey: 'api_live_93a2fb4f-a74a-416f-967d-68557bcde43f'
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'

View File

@ -14,7 +14,6 @@ import org.springframework.util.Assert;
* @author HH 2022/3/25
*/
@Configuration
@ConditionalOnProperty("adapay")
@EnableConfigurationProperties(AdapayProperties.class)
public class AdapayAutoConfiguration {

View File

@ -12,7 +12,10 @@ import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Drawcash;
import com.huifu.adapay.model.Payment;
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 java.util.HashMap;
@ -21,10 +24,13 @@ import java.util.Map;
/**
* @author HH 2022/3/25
*/
@Slf4j
@Setter
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,
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);
paymentParams.put("app_id", adapayProperties.getAppId());
paymentParams.put("notify_url", adapayProperties.getNotifyUrl());
@ -112,6 +112,10 @@ public class AdapayService {
paymentParams.put("description", description);
paymentParams.put("expend", expend);
PayReplyMapping.putCallback(orderNo, callback);
paymentParams.forEach((key,value)->{
logger.info("key is " + key + ", value is " + value);
});
return Payment.create(paymentParams);
}

View File

@ -5,8 +5,9 @@ import com.ghy.common.adapay.callback.mapping.PayReplyMapping;
import com.ghy.common.adapay.callback.mapping.RefundReplyMapping;
import com.huifu.adapay.core.AdapayCore;
import com.huifu.adapay.core.util.AdapaySign;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -17,21 +18,24 @@ import org.springframework.web.bind.annotation.RestController;
*
* @author HH 2022/3/25
*/
@Slf4j
@RestController
public class AdapayCallbackController {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@PostMapping("/adapay/callback")
public String callback(@RequestBody Event event) {
logger.info(" 收单返回消息event" + event);
//验签请参data
String data = event.getData();
logger.info(" 收单返回消息data" + data);
//验签请参sign
String sign = event.getSign();
boolean verifySign = false;
try {
verifySign = verifySign(data, sign);
} catch (Exception e) {
log.error("签名验证失败 {}", e.getMessage());
logger.error("签名验证失败 {}", e.getMessage());
}
if (verifySign) {
//Event事件类型
@ -53,12 +57,12 @@ public class AdapayCallbackController {
DrawCashReplyMapping.putReply(event);
break;
default:
log.warn("UNKNOWN EVENT TYPE [{}]", type);
logger.warn("UNKNOWN EVENT TYPE [{}]", type);
return "NG";
}
return "OK";
}
log.warn("签名验证失败 data=[{}], sign=[{}]", data, sign);
logger.warn("签名验证失败 data=[{}], sign=[{}]", data, sign);
return "NG";
}
@ -74,7 +78,7 @@ public class AdapayCallbackController {
Assert.hasText(sign, "sign is blank!");
//验签请参publicKey
String publicKey = AdapayCore.PUBLIC_KEY;
log.debug("验签请参data={}sign={}", data, sign);
logger.debug("验签请参data={}sign={}", data, sign);
//验签
return AdapaySign.verifySign(data, sign, publicKey);
}

View File

@ -277,6 +277,7 @@ public class ShiroConfig
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
//部分接口不需要登陆校验
filterChainDefinitionMap.put("/wx/**", "anon");
filterChainDefinitionMap.put("/pay/**", "anon");
filterChainDefinitionMap.put("/adapay/**", "anon");
filterChainDefinitionMap.put("/MP_verify_bRFuvYpyQ4WLr0on.txt", "anon");
// 对静态资源设置匿名访问