公众号支付 + 回调解析 + 配置文件补充
This commit is contained in:
parent
d11d8cb3f9
commit
9956a2bd7d
|
|
@ -1,6 +1,9 @@
|
||||||
package com.ghy.web.controller.pay;
|
package com.ghy.web.controller.pay;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ghy.common.adapay.AdapayService;
|
||||||
|
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.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
import com.ghy.common.utils.WxUtils;
|
import com.ghy.common.utils.WxUtils;
|
||||||
|
|
@ -15,11 +18,13 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
@RequestMapping("/pay/wx")
|
@RequestMapping("/pay/wx")
|
||||||
public class WxPayController extends BaseController {
|
public class WxPayController extends BaseController {
|
||||||
|
|
||||||
|
private AdapayService adapayService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信公众号支付.
|
* 微信公众号支付.
|
||||||
* https://open.weixin.qq.com/connect/oauth2/authorize?
|
* https://open.weixin.qq.com/connect/oauth2/authorize?
|
||||||
* appid=wx404f2439a8c24e15
|
* appid=wx404f2439a8c24e15
|
||||||
* &redirect_uri=http%3A%2F%2Fwww.opsoul.com%2Fwx%2Fopenid
|
* &redirect_uri=http%3A%2F%2Fwww.opsoul.com%2Fpay%2Fwx%2Fpub
|
||||||
* &response_type=code
|
* &response_type=code
|
||||||
* &scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect
|
* &scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect
|
||||||
* */
|
* */
|
||||||
|
|
@ -27,17 +32,21 @@ 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");
|
||||||
|
//测试时前端不带订单号.
|
||||||
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");
|
||||||
//调用adapay微信公众号支付.
|
//调用adapay微信公众号支付.
|
||||||
|
WxLiteExpend expend = new WxLiteExpend();
|
||||||
|
expend.setOpen_id(openId);
|
||||||
|
adapayService.wxPubPay(new WxPubPayCallBack(), expend, "wxPay123456" + Math.ceil(Math.random()*100), "1.00",
|
||||||
|
"测试商品", "测试商品detail", "description");
|
||||||
//拼接消息给前端.前端通过JSAPI调用微信支付
|
//拼接消息给前端.前端通过JSAPI调用微信支付
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,8 @@ qiniu:
|
||||||
mediaUrl: 'http://gqz.opsoul.com/'
|
mediaUrl: 'http://gqz.opsoul.com/'
|
||||||
|
|
||||||
adapay:
|
adapay:
|
||||||
appId:
|
appId: 'app_01af32e7-6173-414f-88e5-79cae64d5e24'
|
||||||
notifyUrl:
|
notifyUrl: 'http://www.opsoul.com/adapay/callback'
|
||||||
apiKey:
|
apiKey: 'api_live_93a2fb4f-a74a-416f-967d-68557bcde43f'
|
||||||
mockApiKey:
|
mockApiKey: 'api_test_88bf2958-583d-41cd-a987-01fe767ff056'
|
||||||
rsaPrivateKey:
|
rsaPrivateKey: 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxcoRizdqBD3pEYVlJg/BkmNoHA2T/craoCKKh2rjBo3GKmuug6mHi+gesxtiGe6arcNU7Yv20rSySHw/rKpp7pNHivLrV4lHWjIVfV/2OCTpPzAbEoWr2nfx9UhQxru5Jue/fsO6VjPv27sFMXJ8pRmqok+eRDUqjuEEKr74oQwIDAQAB'
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ 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.Setter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
@ -23,7 +22,6 @@ import java.util.Map;
|
||||||
* @author HH 2022/3/25
|
* @author HH 2022/3/25
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Setter
|
|
||||||
public class AdapayService {
|
public class AdapayService {
|
||||||
|
|
||||||
AdapayProperties adapayProperties;
|
AdapayProperties adapayProperties;
|
||||||
|
|
@ -68,6 +66,14 @@ public class AdapayService {
|
||||||
return pay(callback, PayChannelEnum.ALIPAY_QR.getCode(), expend, orderNo, payAmt, goodsTittle, goodsDesc, description);
|
return pay(callback, PayChannelEnum.ALIPAY_QR.getCode(), expend, orderNo, payAmt, goodsTittle, goodsDesc, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信小程序支付
|
||||||
|
*/
|
||||||
|
public Map<String, Object> wxPubPay(PayCallback callback, WxLiteExpend expend, String orderNo, String payAmt,
|
||||||
|
String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
|
||||||
|
return pay(callback, PayChannelEnum.WX_PUB.getCode(), expend, orderNo, payAmt, goodsTittle, goodsDesc, description);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信小程序支付
|
* 微信小程序支付
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ package com.ghy.common.adapay;
|
||||||
public enum PayChannelEnum {
|
public enum PayChannelEnum {
|
||||||
|
|
||||||
ALIPAY_QR("alipay_qr", "支付宝正扫"),
|
ALIPAY_QR("alipay_qr", "支付宝正扫"),
|
||||||
WX_LITE("wx_lite", "wx_lite");
|
WX_LITE("wx_lite", "微信小程序"),
|
||||||
|
WX_PUB("wx_pub", "微信公众号");
|
||||||
|
|
||||||
private final String code;
|
private final String code;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
package com.ghy.common.adapay.callback.model;
|
package com.ghy.common.adapay.callback.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HH 2022/3/31
|
* @author HH 2022/3/31
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class Expend {
|
public class Expend {
|
||||||
|
|
||||||
|
private String open_id;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ghy.common.adapay.callback.reply;
|
||||||
|
|
||||||
|
import com.ghy.common.adapay.callback.PayCallback;
|
||||||
|
import com.ghy.common.adapay.callback.model.PayReply;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class WxPubPayCallBack implements PayCallback {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReply(PayReply reply) {
|
||||||
|
// 更新工单状态
|
||||||
|
log.info("wx pub pay response is : " + reply.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -277,8 +277,9 @@ 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("/adapay/**", "anon");
|
||||||
filterChainDefinitionMap.put("/MP_verify_bRFuvYpyQ4WLr0on.txt", "anon");
|
filterChainDefinitionMap.put("/MP_verify_bRFuvYpyQ4WLr0on.txt", "anon");
|
||||||
|
// 对静态资源设置匿名访问
|
||||||
filterChainDefinitionMap.put("/favicon.ico**", "anon");
|
filterChainDefinitionMap.put("/favicon.ico**", "anon");
|
||||||
filterChainDefinitionMap.put("/ruoyi.png**", "anon");
|
filterChainDefinitionMap.put("/ruoyi.png**", "anon");
|
||||||
filterChainDefinitionMap.put("/html/**", "anon");
|
filterChainDefinitionMap.put("/html/**", "anon");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue