| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SortedMap<Object, Object> miniAppPay(String body, String orderId, int totalFee, Long poleId, String wxCode) throws WxErrorException { |
| | | public SortedMap<Object, Object> miniAppPay(HttpServletRequest request, String body, String orderId, int totalFee, Long poleId, String wxCode) throws WxErrorException { |
| | | WxConfigEntity wxConfig = wxPayConfigService.getConfigByPoleId(poleId); |
| | | |
| | | //设置微信支付参数 |
| | | WxPayConfig payConfig = new WxPayConfig(); |
| | | |
| | | payConfig.setAppId(StringUtils.trimToNull(wxConfig.getAppid())); |
| | | payConfig.setAppId(StringUtils.trimToNull(wxConfig.getAppappid())); |
| | | payConfig.setMchId(StringUtils.trimToNull(wxConfig.getMchId())); |
| | | payConfig.setMchKey(StringUtils.trimToNull(wxConfig.getPrivateKey())); |
| | | payConfig.setSubAppId(StringUtils.trimToNull(null)); |
| | | payConfig.setSubMchId(StringUtils.trimToNull(null)); |
| | | payConfig.setKeyPath(StringUtils.trimToNull(null)); |
| | | wxPayService.setConfig(payConfig); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //设置微信同一订单请求 |
| | |
| | | |
| | | |
| | | wxPayUnifiedOrderRequest.setSignType(WxPayConstants.SignType.MD5); |
| | | wxPayUnifiedOrderRequest.setSpbillCreateIp(IpUtil.getRealIp()); |
| | | wxPayUnifiedOrderRequest.setSpbillCreateIp(IpUtil.getIpAddr(request)); |
| | | wxPayUnifiedOrderRequest.setNotifyUrl(WECHAT_ORDER_PAY_CALLBACK_URL); |
| | | wxPayUnifiedOrderRequest.setTradeType(WxPayConstants.TradeType.JSAPI); |
| | | System.out.println("-----------" + wxPayUnifiedOrderRequest); |
| | |
| | | SortedMap<Object, Object> parameters = new TreeMap<>(); |
| | | parameters.put("appid", wxPayUnifiedOrderResult.getAppid()); |
| | | |
| | | parameters.put("noncestr", wxPayUnifiedOrderResult.getNonceStr()); // 随机字符串 |
| | | // parameters.put("noncestr", wxPayUnifiedOrderResult.getNonceStr()); // 随机字符串 |
| | | parameters.put("partnerid", wxConfig.getMchId()); // 商户id |
| | | |
| | | // parameters.put("out_trade_no", orderId);//商户订单号 |
| | | parameters.put("prepayid", wxPayUnifiedOrderResult.getPrepayId()); |
| | | parameters.put("package", "Sign=WXPay"); |
| | | parameters.put("timestamp", time); |
| | | // parameters.put("package", "Sign=WXPay"); |
| | | // parameters.put("timestamp", time); |
| | | |
| | | String sign = createSign(wxConfig.getPrivateKey(), parameters); |
| | | |
| | |
| | | throw new BusinessException("找不到微信配置"); |
| | | } |
| | | WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); |
| | | config.setAppid(wxConfig.getAppid()); |
| | | config.setAppid(wxConfig.getAppappid()); |
| | | config.setSecret(wxConfig.getAppSecret()); |
| | | WxMaService service = new WxMaServiceImpl(); |
| | | service.setWxMaConfig(config); |
| | |
| | | |
| | | public String getOpenId(Long poleId, String wxCode) throws WxErrorException { |
| | | WxConfigEntity userConfig = wxPayConfigService.getConfigByPoleId(poleId); |
| | | WxConfigEntity wxConfig = new WxConfigEntity(); |
| | | wxConfig.setAppid(userConfig.getAppid()); |
| | | wxConfig.setMchId(userConfig.getMchId()); |
| | | wxConfig.setPrivateKey(userConfig.getPrivateKey()); |
| | | wxConfig.setAppSecret(userConfig.getAppSecret()); |
| | | if (wxConfig == null) { |
| | | if (userConfig == null) { |
| | | throw new BusinessException("找不到微信配置"); |
| | | } |
| | | WxMaJscode2SessionResult sessionInfo = this.getWxMaService(wxConfig).getUserService().getSessionInfo(wxCode); |
| | | WxMaJscode2SessionResult sessionInfo = this.getWxMaService(userConfig).getUserService().getSessionInfo(wxCode); |
| | | return sessionInfo.getOpenid(); |
| | | } |
| | | |