|
@@ -0,0 +1,485 @@
|
|
|
|
+package com.hcloud.microserver.bank.controller.web;
|
|
|
|
+
|
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
|
+import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
|
+import com.hcloud.microserver.bank.biz.WechatManagerComponent;
|
|
|
|
+import com.hcloud.microserver.bank.common.BaseInfoDO;
|
|
|
|
+import com.hcloud.microserver.bank.common.CarbonBaseController;
|
|
|
|
+import com.hcloud.microserver.bank.config.WxMpConfiguration;
|
|
|
|
+import com.hcloud.microserver.bank.service.OrderInfoService;
|
|
|
|
+import com.hcloud.microserver.bank.service.OrderPayService;
|
|
|
|
+import com.hcloud.microserver.commoncore.annotation.AuthCarbonValidate;
|
|
|
|
+import com.hcloud.microserver.commoncore.base.ResponseBase;
|
|
|
|
+import com.hcloud.microserver.commoncore.base.ResultVO;
|
|
|
|
+import com.hcloud.microserver.commoncore.constant.GlobleConstant;
|
|
|
|
+import com.hcloud.microserver.commoncore.enums.ResultEnum;
|
|
|
|
+import com.hcloud.microserver.commoncore.service.RedisUtils;
|
|
|
|
+import com.hcloud.microserver.commoncore.util.GeneratorIdUtils;
|
|
|
|
+import com.hcloud.microserver.commoncore.util.HttpKit;
|
|
|
|
+import com.hcloud.microserver.commoncore.util.UUIDUtils;
|
|
|
|
+import com.hcloud.microserver.facade.carbon.forms.CustomerInfoForm;
|
|
|
|
+import com.hcloud.microserver.facade.carbon.forms.GoodsOrderInfoForm;
|
|
|
|
+import com.hcloud.microserver.facade.carbon.forms.GoodsPayOrderForm;
|
|
|
|
+import io.swagger.annotations.*;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
+import me.chanjar.weixin.common.util.http.URIUtil;
|
|
|
|
+import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
|
+import me.chanjar.weixin.mp.api.WxMpUserService;
|
|
|
|
+import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
|
|
+import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.security.GeneralSecurityException;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author xiezt
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/wap/weChat")
|
|
|
|
+@Api(description = "H5微信api服务")
|
|
|
|
+public class WechatManagerController extends CarbonBaseController {
|
|
|
|
+
|
|
|
|
+ private static final String WECHAT_AUTH_SCOPE="snsapi_userinfo";
|
|
|
|
+
|
|
|
|
+ private static final String WECHAT_AUTH_BASE_SCOPE="snsapi_base";
|
|
|
|
+
|
|
|
|
+ private static final String WECHAT_USER_INFO="wechatUserInfo";
|
|
|
|
+
|
|
|
|
+ private static final String WECHAT_PAY_FLAG_TEST="test";
|
|
|
|
+
|
|
|
|
+ private static final String WECHAT_INFO_PREFIX="weChatInfoPrefix_";
|
|
|
|
+
|
|
|
|
+ @Value("${wx.mp.appId}")
|
|
|
|
+ private String appid;
|
|
|
|
+
|
|
|
|
+ @Value("${wx.auth.redirecturl}")
|
|
|
|
+ private String wechatRedirectUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${wx.auth.baseurl}")
|
|
|
|
+ private String weChatBaseUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${wx.pay.flag}")
|
|
|
|
+ private String payFlag;
|
|
|
|
+
|
|
|
|
+ @Value("${wx.auth.wxpaycallbackurl}")
|
|
|
|
+ private String wxpayCallbackUrl;
|
|
|
|
+
|
|
|
|
+ private String weChatForwardUrl;
|
|
|
|
+ /**
|
|
|
|
+ * 静默授权时
|
|
|
|
+ */
|
|
|
|
+ private String currentCustomerId;
|
|
|
|
+
|
|
|
|
+ private String globalToken;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private WechatManagerComponent weChatManager;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private WxPayService wxPayService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OrderInfoService orderClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OrderPayService orderPayClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtils redisUtils;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "微信登录",notes = "微信登录")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "furl",value = "授权成功后的", dataType = "String",paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "authScope",value = "授权范围", dataType = "Integer",paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "token",value = "当前用户token", dataType = "String",paramType = "query")
|
|
|
|
+ })
|
|
|
|
+ @ApiResponse(code =0,message = "查询成功")
|
|
|
|
+ @GetMapping("/login")
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ public void login(@RequestParam("furl") String furl,
|
|
|
|
+ Integer authScope,
|
|
|
|
+ String token){
|
|
|
|
+ if(null!=furl && !"".equals(weChatForwardUrl)){
|
|
|
|
+ weChatForwardUrl = furl;
|
|
|
|
+ }
|
|
|
|
+ if(Objects.nonNull(token)){
|
|
|
|
+ BaseInfoDO baseInfoDO = this.initiSaveObject(token);
|
|
|
|
+ if(Objects.nonNull(baseInfoDO)){
|
|
|
|
+ //登录失效跳转登录首页
|
|
|
|
+ currentCustomerId=baseInfoDO.getCustomerId();
|
|
|
|
+ }
|
|
|
|
+ globalToken = token;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ log.info("currentCustomerId is ================>{}",currentCustomerId);
|
|
|
|
+ final WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appid);
|
|
|
|
+ String authUrls = "";
|
|
|
|
+ if(authScope==2){
|
|
|
|
+ authUrls= wxMpService.getOAuth2Service().buildAuthorizationUrl(weChatBaseUrl,WECHAT_AUTH_BASE_SCOPE, URIUtil.encodeURIComponent(weChatForwardUrl));
|
|
|
|
+ }else{
|
|
|
|
+ authUrls= wxMpService.getOAuth2Service().buildAuthorizationUrl(wechatRedirectUrl,WECHAT_AUTH_SCOPE, URIUtil.encodeURIComponent(weChatForwardUrl));
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ log.info("authUrls===============>{}",authUrls);
|
|
|
|
+ this.getResponseObject().sendRedirect(authUrls);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.error("请求微信权限地址错误请检查配置参数,配置的url:{}",authUrls);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "获取微信用户基本信息",notes = "微信静默授权接口请勿随意调用")
|
|
|
|
+ @ApiResponse(code =500,message = "请求的配置参数有问题")
|
|
|
|
+ @GetMapping("/baseLogin")
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ public void baseLogin(@RequestParam("code") String code){
|
|
|
|
+ log.info("currentCustomerId======================>{}",currentCustomerId);
|
|
|
|
+ log.info("global token==========================>{}",globalToken);
|
|
|
|
+ if(null!=code && !"".equals(code)){
|
|
|
|
+ log.info("微信权限认证code是====================>{}",code);
|
|
|
|
+ final WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appid);
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ WxMpOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
|
|
|
|
+// WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
|
|
|
|
+ if(accessToken!=null ){
|
|
|
|
+ log.info("accessToken object is:{}",accessToken);
|
|
|
|
+ WxMpUserService userService = wxMpService.getUserService();
|
|
|
|
+ WxMpUser wxMpUser = userService.userInfo(accessToken.getAccessToken());
|
|
|
|
+// WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken,"");
|
|
|
|
+ log.info("wxMpUser object is:{}",wxMpUser);
|
|
|
|
+ if(null!=currentCustomerId && !"".equals(currentCustomerId)){
|
|
|
|
+ //微信授权信息写入登录缓存用户微信支付
|
|
|
|
+ Map resultMap = (Map) redisUtils.getValue(globalToken);
|
|
|
|
+ if(Objects.nonNull(resultMap)){
|
|
|
|
+ resultMap.put(GlobleConstant.WECHAT_INFO_PREFIX,wxMpUser);
|
|
|
|
+ }
|
|
|
|
+ redisUtils.setValue(globalToken,resultMap, GlobleConstant.TOKEN_EXPIRES_SECOND,TimeUnit.SECONDS);
|
|
|
|
+ }
|
|
|
|
+ this.getResponseObject().sendRedirect(weChatForwardUrl);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("微信参数错误,请查看参数配置谢谢");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "获取微信用户信息",notes = "微信回调接口请勿直接请求")
|
|
|
|
+ @ApiResponse(code =500,message = "请求的配置参数有问题")
|
|
|
|
+ @GetMapping("/doLogin")
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ public void doLogin(@RequestParam("code") String code){
|
|
|
|
+ if(null!=code && !"".equals(code)){
|
|
|
|
+ log.info("微信权限认证code是====================>{}",code);
|
|
|
|
+ final WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appid);
|
|
|
|
+ try {
|
|
|
|
+ WxMpOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
|
|
|
|
+// WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
|
|
|
|
+ if(accessToken!=null ){
|
|
|
|
+ log.info("accessToken object is:{}",accessToken);
|
|
|
|
+ WxMpUserService userService = wxMpService.getUserService();
|
|
|
|
+ WxMpUser wxMpUser = userService.userInfo(accessToken.getAccessToken());
|
|
|
|
+// WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken,"");
|
|
|
|
+ log.info("wxMpUser object is:{}",wxMpUser);
|
|
|
|
+ Map map = weChatManager.getWechatAccessToken(wxMpUser);
|
|
|
|
+ if(null!=map && map.size()>0){
|
|
|
|
+ String token = (String) map.get(GlobleConstant.ACCESS_TOKEN);
|
|
|
|
+ log.info("redirectUrl======================>{}",weChatForwardUrl+"?accessToken="+token);
|
|
|
|
+ this.getResponseObject().sendRedirect(weChatForwardUrl+"?accessToken="+token);
|
|
|
|
+ }else {
|
|
|
|
+ this.getResponseObject().sendRedirect(weChatForwardUrl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("微信参数错误,请查看参数配置谢谢");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "退出登录",notes = "退出登录,删除缓存信息")
|
|
|
|
+ @ApiResponse(code =500,message = "请求的配置参数有问题")
|
|
|
|
+ @GetMapping("/logout")
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ public ResponseBase logout(){
|
|
|
|
+ BaseInfoDO baseInfoDO = this.initiSaveObject();
|
|
|
|
+ if(baseInfoDO==null){responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));}
|
|
|
|
+ String accessToken = this.getRequestObject().getHeader(ACCESS_TOKEN);
|
|
|
|
+ redisUtils.deleteKey(accessToken);
|
|
|
|
+ return responseSuccess(new ResultVO(ResultEnum.SUCCESS));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "微信支付接口(二次支付)",notes = "微信支付接口请勿随意调用(二次支付)")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "orderId",value = "订单编号", dataType = "String",paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "tradeType",value = "交易方式(NATIVE,APP,JSAPI,MWEB)", dataType = "String",paramType = "query")
|
|
|
|
+ })
|
|
|
|
+ @ApiResponse(code =500,message = "请求的配置参数有问题")
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ @GetMapping("/pay")
|
|
|
|
+ public ResponseBase pay(@RequestParam("orderId") String orderId,
|
|
|
|
+ @RequestParam("tradeType") String tradeType){
|
|
|
|
+ try {
|
|
|
|
+ BaseInfoDO baseInfoDO = this.initiSaveObject();
|
|
|
|
+ WxMpUser wxMpUser = this.initiWwChatInfo();
|
|
|
|
+ if(Objects.isNull(baseInfoDO)){
|
|
|
|
+ return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));
|
|
|
|
+ }
|
|
|
|
+ //验证商品订单是否已经支付
|
|
|
|
+ GoodsOrderInfoForm orderInfoById = orderClient.getOrderInfoById(orderId);
|
|
|
|
+ if(orderInfoById==null){
|
|
|
|
+ return responseEnum(ResultEnum.ORDER_PAY_DUPLICATE);
|
|
|
|
+ }
|
|
|
|
+// Map orderInfoMap = (Map) resultVO.getData();
|
|
|
|
+// log.info("orderInfoMap=======================>{}",orderInfoMap);
|
|
|
|
+// Double payMoney = (Double) orderInfoMap.get("orderAmount");
|
|
|
|
+// Double orderCarbonAmount = (Double) orderInfoMap.get("orderCarbonAmount");
|
|
|
|
+// JavaBeanUtils.mapToEntity(orderInfoMap, GoodsOrderInfoForm.class);
|
|
|
|
+ GoodsOrderInfoForm orderInfoForm = orderInfoById;
|
|
|
|
+ Double payMoney = Double.valueOf(orderInfoById.getOrderAmount().toString());
|
|
|
|
+ Double orderCarbonAmount = Double.valueOf(orderInfoById.getOrderCarbonAmount().toString());
|
|
|
|
+ log.info("orderInfo===================>{}",orderInfoForm);
|
|
|
|
+ if(orderInfoForm.getOrderStatus()!=1){
|
|
|
|
+ return responseError(new ResultVO(ResultEnum.ORDER_PAY_COMPLETE));
|
|
|
|
+ }
|
|
|
|
+ CustomerInfoForm customerInfoForm = weChatManager.getCustomerInfoByCustomerId(orderInfoForm.getFkCustomerGuid());
|
|
|
|
+ log.info("customerInfo=======================>{}",customerInfoForm);
|
|
|
|
+ //生成支付订单,并返回支付订单编号
|
|
|
|
+ BigDecimal orderAmount = BigDecimal.valueOf(payMoney);
|
|
|
|
+ orderInfoForm.setOrderAmount(orderAmount);
|
|
|
|
+ String payNo = this.insertPayOrderInfo(orderInfoForm);
|
|
|
|
+ if(payNo==null){return responseError(new ResultVO(308,"支付订单生成失败"));}
|
|
|
|
+ log.info("pay order no=======================>{}",payNo);
|
|
|
|
+ //调用微信统一下单接口
|
|
|
|
+ log.info("money=====================>{}",payMoney);
|
|
|
|
+ Object unOrder = null;
|
|
|
|
+ if(WxPayConstants.TradeType.JSAPI.equals(tradeType)){
|
|
|
|
+ unOrder = this.wxUnifiedOrder(payNo,orderAmount,tradeType,wxMpUser.getOpenId());
|
|
|
|
+ }else{
|
|
|
|
+ unOrder = this.wxUnifiedOrder(payNo,orderAmount,tradeType,null);
|
|
|
|
+ }
|
|
|
|
+ log.info("pay order result======================>{}",unOrder);
|
|
|
|
+ //支付倒计时
|
|
|
|
+ GoodsPayOrderForm payOrderForm = orderPayClient.getPayOrderByNo(payNo);
|
|
|
|
+// ResultVO payOrderVo = orderPayClient.getPayOrderInfoByPayNo(payNo);
|
|
|
|
+// Map payOrderMap = (Map) payOrderVo.getData();
|
|
|
|
+// log.info("payOrderMap=================>{}",payOrderMap);
|
|
|
|
+// GoodsPayOrderForm payOrderForm = JavaBeanUtils.mapToEntity(payOrderMap, GoodsPayOrderForm.class);
|
|
|
|
+ String orderKey ="ord:"+payOrderForm.getOrderNo();
|
|
|
|
+ redisUtils.setValue(orderKey,payOrderForm,900,TimeUnit.SECONDS);
|
|
|
|
+ return responseSuccess(success(unOrder));
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ return responseError(failure());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "微信支付结果回调",notes = "微信支付结果回调请勿直接调用")
|
|
|
|
+ @ApiResponse(code =500,message = "请求的配置参数有问题")
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ @PostMapping("/payResultNotified")
|
|
|
|
+ public String payOrderResultNotify(HttpServletRequest request){
|
|
|
|
+ String xmlResult = HttpKit.readData(request);
|
|
|
|
+ boolean isPayOk = false;
|
|
|
|
+ WxPayOrderNotifyResult wxPayOrderNotifyResult = null;
|
|
|
|
+ try {
|
|
|
|
+ wxPayOrderNotifyResult = wxPayService.parseOrderNotifyResult(xmlResult);
|
|
|
|
+ if (WxPayConstants.ResultCode.SUCCESS.equals(wxPayOrderNotifyResult.getResultCode())) {
|
|
|
|
+ isPayOk = true;
|
|
|
|
+ }
|
|
|
|
+ log.info("WxPayOrderNotifyResult is ===================>{}",wxPayOrderNotifyResult);
|
|
|
|
+ if(isPayOk){
|
|
|
|
+ String payNo = wxPayOrderNotifyResult.getOutTradeNo();
|
|
|
|
+ // 更新订单信息(含商品订单,支付订单信息)
|
|
|
|
+ int i = orderClient.updateFullOrderInfo(payNo, 2);
|
|
|
|
+// ResultVO resultVO = orderClient.updateOrderInfoAndPayOrderInfo(payNo);
|
|
|
|
+ if(i<1){
|
|
|
|
+ log.error("更新订单信息失败,请联系开发人员");
|
|
|
|
+ return setXML("FAIL", "");
|
|
|
|
+ }
|
|
|
|
+ //删除已支付成功的支付订单缓存信息
|
|
|
|
+ GoodsPayOrderForm goodsPayOrderForm = orderPayClient.getPayOrderByNo(payNo);
|
|
|
|
+ GoodsPayOrderForm payOrderForm = goodsPayOrderForm;
|
|
|
|
+// ResultVO payOrderVo = orderPayClient.getPayOrderInfoByPayNo(payNo);
|
|
|
|
+// Map payOrderMap = (Map) payOrderVo.getData();
|
|
|
|
+// GoodsPayOrderForm payOrderForm = JavaBeanUtils.mapToEntity(payOrderMap, GoodsPayOrderForm.class);
|
|
|
|
+ redisUtils.deleteKey("ord:"+payOrderForm.getOrderNo());
|
|
|
|
+ //返回响应信息给微信接口
|
|
|
|
+ return setXML("SUCCESS", "OK");
|
|
|
|
+ }else {
|
|
|
|
+ // 支付失败, 记录流水失败
|
|
|
|
+ return setXML("FAIL", "");
|
|
|
|
+ }
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ log.info("微信支付通知失败,请联系开发人员");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return setXML("FAIL", "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "微信js签名接口", notes = "微信js签名接口")
|
|
|
|
+ @ApiResponses({
|
|
|
|
+ @ApiResponse(code = 0, message = "成功")
|
|
|
|
+ })
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ @GetMapping("getJsapiTicket")
|
|
|
|
+ public ResponseBase getJsapiTicket(String url) {
|
|
|
|
+ final WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appid);
|
|
|
|
+ WxJsapiSignature jsapiSignature = null;
|
|
|
|
+ ResultVO resultVO = new ResultVO();
|
|
|
|
+ try {
|
|
|
|
+ jsapiSignature = wxMpService.createJsapiSignature(url);
|
|
|
|
+ resultVO.setCode(ResultEnum.SUCCESS.getCode());
|
|
|
|
+ resultVO.setData(jsapiSignature);
|
|
|
|
+ } catch (WxErrorException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ System.err.print(e.getError());
|
|
|
|
+ resultVO.setCode(ResultEnum.FAILURE.getCode());
|
|
|
|
+ resultVO.setData("微信js签名失败");
|
|
|
|
+ }
|
|
|
|
+ return responseSuccess(resultVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "微信授权信息检测", notes = "检测是否已经有微信授权信息")
|
|
|
|
+ @ApiResponses({
|
|
|
|
+ @ApiResponse(code = 0, message = "微信已授权")
|
|
|
|
+ })
|
|
|
|
+ @AuthCarbonValidate
|
|
|
|
+ @GetMapping("/checkWxMap")
|
|
|
|
+ public ResponseBase checkWxMap(){
|
|
|
|
+ Map resultMap = new HashMap();
|
|
|
|
+ WxMpUser wxMpUser = this.initiWwChatInfo();
|
|
|
|
+ if(Objects.nonNull(wxMpUser)){
|
|
|
|
+ resultMap.put("status",1);
|
|
|
|
+ return responseSuccess(success(resultMap));
|
|
|
|
+ }
|
|
|
|
+ resultMap.put("status",0);
|
|
|
|
+ return responseError(success(resultMap));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成支付订单
|
|
|
|
+ * @param orderInfoForm
|
|
|
|
+ */
|
|
|
|
+ private String insertPayOrderInfo(GoodsOrderInfoForm orderInfoForm){
|
|
|
|
+ if(null!= orderInfoForm && !"".equals(orderInfoForm.getOrderNo())){
|
|
|
|
+ GeneratorIdUtils generatorIdUtils = new GeneratorIdUtils();
|
|
|
|
+ String orderNum = generatorIdUtils.nextId();
|
|
|
|
+ GoodsPayOrderForm goodsPayOrderForm = new GoodsPayOrderForm();
|
|
|
|
+ goodsPayOrderForm.setFkCustomerId(orderInfoForm.getFkCustomerGuid());
|
|
|
|
+ goodsPayOrderForm.setFkOrderId(orderInfoForm.getGuid());
|
|
|
|
+ goodsPayOrderForm.setOrderNo(orderInfoForm.getOrderNo());
|
|
|
|
+ goodsPayOrderForm.setPayAmount(orderInfoForm.getOrderAmount());
|
|
|
|
+ goodsPayOrderForm.setPayChannel(1);
|
|
|
|
+ goodsPayOrderForm.setPayStatus(1);
|
|
|
|
+ goodsPayOrderForm.setPayNo(orderNum);
|
|
|
|
+ goodsPayOrderForm.setPayTime(new Date());
|
|
|
|
+ log.info("goodsPayOrderForm==================>{}",goodsPayOrderForm);
|
|
|
|
+ int i = orderPayClient.saveSelective(goodsPayOrderForm);
|
|
|
|
+// ResultVO resultVO = orderPayClient.savePayOrderInfo(goodsPayOrderForm);
|
|
|
|
+ if(i>0){
|
|
|
|
+ return orderNum;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 微信统一下单
|
|
|
|
+ * @param payNo 支付订单号
|
|
|
|
+ * @param money 支付金额
|
|
|
|
+ * @param tradeType 交易类型
|
|
|
|
+ * @param wxId 微信openid(只用于jsaip交易方式)
|
|
|
|
+ * @return
|
|
|
|
+ * @throws WxPayException
|
|
|
|
+ */
|
|
|
|
+ private Object wxUnifiedOrder(String payNo,BigDecimal money,String tradeType,String wxId) throws WxPayException {
|
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
|
+ orderRequest.setNonceStr(UUIDUtils.randomUUID());
|
|
|
|
+ //商品描述
|
|
|
|
+ orderRequest.setBody("碳汇+平台购买商品");
|
|
|
|
+ //商户订单号(支付编号)
|
|
|
|
+ orderRequest.setOutTradeNo(payNo);
|
|
|
|
+ //元转成分
|
|
|
|
+ BigDecimal cmoney = money.multiply(new BigDecimal(100));
|
|
|
|
+ int i = cmoney.intValue();
|
|
|
|
+ if(WECHAT_PAY_FLAG_TEST.equalsIgnoreCase(payFlag)){
|
|
|
|
+ orderRequest.setTotalFee(1);
|
|
|
|
+ }else{
|
|
|
|
+ orderRequest.setTotalFee(i);
|
|
|
|
+ }
|
|
|
|
+ //终端ip
|
|
|
|
+ orderRequest.setSpbillCreateIp(getIpAddress(this.getRequestObject()));
|
|
|
|
+ // 通知地址 支付成功后跳转页面
|
|
|
|
+ log.info("wxpayCallbackUrl=================>{}", wxpayCallbackUrl);
|
|
|
|
+ orderRequest.setNotifyUrl(wxpayCallbackUrl);
|
|
|
|
+ //交易类型
|
|
|
|
+ orderRequest.setTradeType(tradeType);
|
|
|
|
+ //用户标识 获取用户openid
|
|
|
|
+ if(wxId!=null){
|
|
|
|
+ orderRequest.setOpenid(wxId);
|
|
|
|
+ }
|
|
|
|
+ // 这个可能是偏向原生一点的统一下单,返回的参数有很多没用的 或者null值 建议使用 createOrder下单
|
|
|
|
+ return wxPayService.createOrder(orderRequest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * //签名成功生成支付订单
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ * @throws GeneralSecurityException
|
|
|
|
+ */
|
|
|
|
+ private void insertPayOrder(Object object) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String setXML(String return_code, String return_msg) {
|
|
|
|
+ return "<xml><return_code><![CDATA[" + return_code + "]]></return_code><return_msg><![CDATA[" + return_msg + "]]></return_msg></xml>";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String getIpAddress(HttpServletRequest request) {
|
|
|
|
+ String ip = request.getHeader("x-forwarded-for");
|
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
|
+ ip = request.getHeader("Proxy-Client-IP");
|
|
|
|
+ }
|
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
|
+ ip = request.getHeader("WL-Proxy-Client-IP");
|
|
|
|
+ }
|
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
|
+ ip = request.getHeader("HTTP_CLIENT_IP");
|
|
|
|
+ }
|
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
|
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
|
|
|
+ }
|
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
|
+ ip = request.getRemoteAddr();
|
|
|
|
+ }
|
|
|
|
+ String[] split = ip.split(",");
|
|
|
|
+ ip = split[0];
|
|
|
|
+ return ip;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|