|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
package co.yixiang.app.modules.wechat.rest.controller; |
|
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
|
|
|
|
import co.yixiang.annotation.AnonymousAccess; |
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.ApiResult; |
|
|
|
|
import co.yixiang.constant.SystemConfigConstants; |
|
|
|
@ -45,11 +46,7 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
@ -95,9 +92,10 @@ public class WechatController {
|
|
|
|
|
/** |
|
|
|
|
* jssdk配置 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/wechat/config") |
|
|
|
|
@GetMapping("/wechat/config/{tenantCode}") |
|
|
|
|
@ApiOperation(value = "jssdk配置",notes = "jssdk配置") |
|
|
|
|
public ApiResult<Map<String,Object>> jsConfig(HttpServletRequest request) throws WxErrorException { |
|
|
|
|
public ApiResult<Map<String,Object>> jsConfig(HttpServletRequest request,@PathVariable String tenantCode) throws WxErrorException { |
|
|
|
|
TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); |
|
|
|
|
WxMpService wxService = WxMpConfiguration.getWxMpService(); |
|
|
|
|
String url = request.getParameter("url"); |
|
|
|
|
log.info("url:"+url); |
|
|
|
@ -118,14 +116,15 @@ public class WechatController {
|
|
|
|
|
/** |
|
|
|
|
* 微信小程序接口能力配置 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/wxapp/config") |
|
|
|
|
@GetMapping("/wxapp/config/{tenantCode}") |
|
|
|
|
@ApiOperation(value = "微信小程序接口能力配置",notes = "微信小程序接口能力配置",produces = "text/plain;charset=utf-8") |
|
|
|
|
public String wxAppConfig(@RequestParam(value = "signature") String signature, |
|
|
|
|
@RequestParam(value = "timestamp") String timestamp, |
|
|
|
|
@RequestParam(value = "nonce") String nonce, |
|
|
|
|
@PathVariable String tenantCode, |
|
|
|
|
@RequestParam(name = "echostr", required = false) String echostr) throws WxErrorException { |
|
|
|
|
TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); |
|
|
|
|
WxMaService wxService = WxMaConfiguration.getWxMaService(); |
|
|
|
|
|
|
|
|
|
if( wxService.checkSignature(timestamp,nonce,signature)){ |
|
|
|
|
return echostr; |
|
|
|
|
} |
|
|
|
@ -136,9 +135,11 @@ public class WechatController {
|
|
|
|
|
* 微信支付/充值回调 |
|
|
|
|
*/ |
|
|
|
|
@AnonymousAccess |
|
|
|
|
@PostMapping("/wechat/notify") |
|
|
|
|
@PostMapping("/wechat/notify/{tenantCode}") |
|
|
|
|
@ApiOperation(value = "微信支付充值回调",notes = "微信支付充值回调") |
|
|
|
|
public String renotify(@RequestBody String xmlData) { |
|
|
|
|
public String renotify(@RequestBody String xmlData, @PathVariable String tenantCode) { |
|
|
|
|
log.info("tenantCode:{}",tenantCode); |
|
|
|
|
TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); |
|
|
|
|
try { |
|
|
|
|
WxPayService wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.WECHAT); |
|
|
|
|
if(wxPayService == null) { |
|
|
|
@ -174,6 +175,7 @@ public class WechatController {
|
|
|
|
|
|
|
|
|
|
return WxPayNotifyResponse.success("处理成功!"); |
|
|
|
|
} catch (WxPayException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error(e.getMessage()); |
|
|
|
|
return WxPayNotifyResponse.fail(e.getMessage()); |
|
|
|
|
} |
|
|
|
@ -184,8 +186,10 @@ public class WechatController {
|
|
|
|
|
* 微信退款回调 |
|
|
|
|
*/ |
|
|
|
|
@ApiOperation(value = "退款回调通知处理",notes = "退款回调通知处理") |
|
|
|
|
@PostMapping("/notify/refund") |
|
|
|
|
public String parseRefundNotifyResult(@RequestBody String xmlData) { |
|
|
|
|
@PostMapping("/notify/refund/{tenantCode}") |
|
|
|
|
public String parseRefundNotifyResult(@RequestBody String xmlData,@PathVariable String tenantCode) { |
|
|
|
|
log.info("tenantCode:{}",tenantCode); |
|
|
|
|
TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); |
|
|
|
|
try { |
|
|
|
|
WxPayService wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.WECHAT); |
|
|
|
|
if(wxPayService == null) { |
|
|
|
@ -225,13 +229,15 @@ public class WechatController {
|
|
|
|
|
/** |
|
|
|
|
* 微信验证消息 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping( value = "/wechat/serve",produces = "text/plain;charset=utf-8") |
|
|
|
|
@GetMapping( value = "/wechat/serve/{tenantCode}",produces = "text/plain;charset=utf-8") |
|
|
|
|
@ApiOperation(value = "微信验证消息",notes = "微信验证消息") |
|
|
|
|
public String authGet(@RequestParam(name = "signature", required = false) String signature, |
|
|
|
|
@RequestParam(name = "timestamp", required = false) String timestamp, |
|
|
|
|
@RequestParam(name = "nonce", required = false) String nonce, |
|
|
|
|
@RequestParam(name = "echostr", required = false) String echostr){ |
|
|
|
|
|
|
|
|
|
@RequestParam(name = "echostr", required = false) String echostr, |
|
|
|
|
@PathVariable String tenantCode |
|
|
|
|
){ |
|
|
|
|
TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); |
|
|
|
|
final WxMpService wxService = WxMpConfiguration.getWxMpService(); |
|
|
|
|
if (wxService == null) { |
|
|
|
|
throw new IllegalArgumentException("未找到对应配置的服务,请核实!"); |
|
|
|
@ -247,7 +253,7 @@ public class WechatController {
|
|
|
|
|
/** |
|
|
|
|
*微信获取消息 |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/wechat/serve") |
|
|
|
|
@PostMapping("/wechat/serve/{tenantCode}") |
|
|
|
|
@ApiOperation(value = "微信获取消息",notes = "微信获取消息") |
|
|
|
|
public void post(@RequestBody String requestBody, |
|
|
|
|
@RequestParam("signature") String signature, |
|
|
|
@ -256,11 +262,12 @@ public class WechatController {
|
|
|
|
|
@RequestParam("openid") String openid, |
|
|
|
|
@RequestParam(name = "encrypt_type", required = false) String encType, |
|
|
|
|
@RequestParam(name = "msg_signature", required = false) String msgSignature, |
|
|
|
|
@PathVariable String tenantCode, |
|
|
|
|
HttpServletRequest request, |
|
|
|
|
HttpServletResponse response) throws IOException { |
|
|
|
|
|
|
|
|
|
TenantContextHolder.setTenantId(Long.valueOf(tenantCode)); |
|
|
|
|
WxMpService wxService = WxMpConfiguration.getWxMpService(); |
|
|
|
|
|
|
|
|
|
if (!wxService.checkSignature(timestamp, nonce, signature)) { |
|
|
|
|
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); |
|
|
|
|
} |
|
|
|
|