com.github.binarywang.wxpay.service.WxPayService Java Examples
The following examples show how to use
com.github.binarywang.wxpay.service.WxPayService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YxMiniPayService.java From yshopmall with Apache License 2.0 | 7 votes |
/** * 退款 * @param orderId * @param totalFee * @throws WxPayException */ public void refundOrder(String orderId, Integer totalFee) throws WxPayException { String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl()); if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址"); WxPayService wxPayService = WxPayConfiguration.getWxAppPayService(); WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest(); wxPayRefundRequest.setTotalFee(totalFee);//订单总金额 wxPayRefundRequest.setOutTradeNo(orderId); wxPayRefundRequest.setOutRefundNo(orderId); wxPayRefundRequest.setRefundFee(totalFee);//退款金额 wxPayRefundRequest.setNotifyUrl(apiUrl + "/api/notify/refund"); wxPayService.refund(wxPayRefundRequest); }
Example #2
Source File: ApiTestModule.java From weixin-java-tools with Apache License 2.0 | 6 votes |
@Override public void configure(Binder binder) { try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) { if (inputStream == null) { throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成"); } XmlWxPayConfig config = this.fromXml(XmlWxPayConfig.class, inputStream); WxPayService wxService = new WxPayServiceImpl(); wxService.setConfig(config); binder.bind(WxPayService.class).toInstance(wxService); binder.bind(WxPayConfig.class).toInstance(config); } catch (IOException e) { this.log.error(e.getMessage(), e); } }
Example #3
Source File: WxPayConfiguration.java From mall4j with GNU Affero General Public License v3.0 | 6 votes |
private WxPayService getWxMpPayServiceByAppId(String appid) { WxPayConfig payConfig = new WxPayConfig(); payConfig.setAppId(appid); payConfig.setMchId(wxPay.getMchId()); payConfig.setMchKey(wxPay.getMchKey()); payConfig.setKeyPath(wxPay.getKeyPath()); payConfig.setSignType(WxPayConstants.SignType.MD5); WxPayService wxPayService = new WxPayServiceImpl(); // 打开下面的代码,开启沙箱模式 // if (Objects.equals(profile, "dev")) { // String sandboxSignKey = null; // try { // wxPayService.setConfig(payConfig); // sandboxSignKey = wxPayService.getSandboxSignKey(); // } catch (WxPayException e) { // e.printStackTrace(); // } // payConfig.setUseSandboxEnv(true); // payConfig.setMchKey(sandboxSignKey); // } wxPayService.setConfig(payConfig); return wxPayService; }
Example #4
Source File: WxMaConfiguration.java From charging_pile_cloud with MIT License | 6 votes |
@Bean @ConditionalOnMissingBean public WxPayService wxService() { WxPayConfig payConfig = new WxPayConfig(); payConfig.setAppId(StringUtils.trimToNull(wxPayProperties.getAppId())); payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getMchId())); payConfig.setMchKey(StringUtils.trimToNull(wxPayProperties.getMchKey())); payConfig.setSignType("MD5"); payConfig.setNotifyUrl(StringUtils.trimToNull(wxPayProperties.getNotifyUrl())); // payConfig.setKeyPath(StringUtils.trimToNull(wxPayProperties.getKeyPath())); // 可以指定是否使用沙箱环境 payConfig.setUseSandboxEnv(false); WxPayService wxPayService = new WxPayServiceImpl(); wxPayService.setConfig(payConfig); return wxPayService; }
Example #5
Source File: YxPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 微信公众号支付 * * @param orderId * @param openId 公众号openid * @param body * @param totalFee * @return * @throws WxPayException */ public WxPayMpOrderResult wxPay(String orderId, String openId, String body, Integer totalFee,String attach) throws WxPayException { String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl()); if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址"); WxPayService wxPayService = WxPayConfiguration.getPayService(); WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setTradeType("JSAPI"); orderRequest.setOpenid(openId); orderRequest.setBody(body); orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(totalFee); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify"); orderRequest.setAttach(attach); WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest); return orderResult; }
Example #6
Source File: YxPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 微信H5支付 * * @param orderId * @param body * @param totalFee * @return * @throws WxPayException */ public WxPayMwebOrderResult wxH5Pay(String orderId, String body, Integer totalFee,String attach) throws WxPayException { String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl()); if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址"); WxPayService wxPayService = WxPayConfiguration.getPayService(); WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setTradeType("MWEB"); orderRequest.setBody(body); orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(totalFee); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify"); orderRequest.setAttach(attach); WxPayMwebOrderResult orderResult = wxPayService.createOrder(orderRequest); return orderResult; }
Example #7
Source File: YxPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 微信app支付 * * @param orderId * @param body * @param totalFee * @return * @throws WxPayException */ public WxPayAppOrderResult appPay(String orderId, String body, Integer totalFee, String attach) throws WxPayException { String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl()); if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址"); WxPayService wxPayService = WxPayConfiguration.getAppPayService(); WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setTradeType("APP"); orderRequest.setBody(body); orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(totalFee); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify"); orderRequest.setAttach(attach); WxPayAppOrderResult appOrderResult = wxPayService.createOrder(orderRequest); return appOrderResult; }
Example #8
Source File: YxPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 退款 * @param orderId * @param totalFee * @throws WxPayException */ public void refundOrder(String orderId, Integer totalFee) throws WxPayException { String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl()); if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址"); WxPayService wxPayService = WxPayConfiguration.getPayService(); WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest(); wxPayRefundRequest.setTotalFee(totalFee);//订单总金额 wxPayRefundRequest.setOutTradeNo(orderId); wxPayRefundRequest.setOutRefundNo(orderId); wxPayRefundRequest.setRefundFee(totalFee);//退款金额 wxPayRefundRequest.setNotifyUrl(apiUrl + "/api/notify/refund"); wxPayService.refund(wxPayRefundRequest); }
Example #9
Source File: YxMiniPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 小程序支付 * * @param orderId * @param openId 小程序openid * @param body * @param totalFee * @return * @throws WxPayException */ public WxPayMpOrderResult wxPay(String orderId, String openId, String body, Integer totalFee,String attach) throws WxPayException { String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl()); if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址"); WxPayService wxPayService = WxPayConfiguration.getWxAppPayService(); WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setTradeType("JSAPI"); orderRequest.setOpenid(openId); orderRequest.setBody(body); orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(totalFee); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify"); orderRequest.setAttach(attach); WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest); return orderResult; }
Example #10
Source File: WxPayConfiguration.java From springboot-seed with MIT License | 5 votes |
@Bean @ConditionalOnMissingBean public WxPayService wxService() { WxPayConfig payConfig = new WxPayConfig(); payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId())); payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId())); payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId())); payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath())); WxPayService wxPayService = new WxPayServiceImpl(); wxPayService.setConfig(payConfig); return wxPayService; }
Example #11
Source File: BaseWxPayResult.java From weixin-java-tools with Apache License 2.0 | 5 votes |
/** * 校验返回结果签名. * * @param signType 签名类型 * @param checkSuccess 是否同时检查结果是否成功 */ public void checkResult(WxPayService wxPayService, String signType, boolean checkSuccess) throws WxPayException { //校验返回结果签名 Map<String, String> map = toMap(); if (getSign() != null && !SignUtils.checkSign(map, signType, wxPayService.getConfig().getMchKey())) { this.getLogger().debug("校验结果签名失败,参数:{}", map); throw new WxPayException("参数格式校验错误!"); } //校验结果是否成功 if (checkSuccess) { List<String> successStrings = Lists.newArrayList("SUCCESS", ""); if (!successStrings.contains(StringUtils.trimToEmpty(getReturnCode()).toUpperCase()) || !successStrings.contains(StringUtils.trimToEmpty(getResultCode()).toUpperCase())) { StringBuilder errorMsg = new StringBuilder(); if (getReturnCode() != null) { errorMsg.append("返回代码:").append(getReturnCode()); } if (getReturnMsg() != null) { errorMsg.append(",返回信息:").append(getReturnMsg()); } if (getResultCode() != null) { errorMsg.append(",结果代码:").append(getResultCode()); } if (getErrCode() != null) { errorMsg.append(",错误代码:").append(getErrCode()); } if (getErrCodeDes() != null) { errorMsg.append(",错误详情:").append(getErrCodeDes()); } this.getLogger().error("\n结果业务代码异常,返回结果:{},\n{}", map, errorMsg.toString()); throw WxPayException.from(this); } } }
Example #12
Source File: YxMiniPayService.java From yshopmall with Apache License 2.0 | 5 votes |
/** * 企业打款 * @param openid * @param no * @param userName * @param amount * @throws WxPayException */ public void entPay(String openid,String no,String userName,Integer amount) throws WxPayException{ WxPayService wxPayService = WxPayConfiguration.getWxAppPayService(); EntPayRequest entPayRequest = new EntPayRequest(); entPayRequest.setOpenid(openid); entPayRequest.setPartnerTradeNo(no); entPayRequest.setCheckName("FORCE_CHECK"); entPayRequest.setReUserName(userName); entPayRequest.setAmount(amount); entPayRequest.setDescription("提现"); entPayRequest.setSpbillCreateIp("127.0.0.1"); wxPayService.getEntPayService().entPay(entPayRequest); }
Example #13
Source File: YxPayService.java From yshopmall with Apache License 2.0 | 5 votes |
/** * 企业打款 * @param openid * @param no * @param userName * @param amount * @throws WxPayException */ public void entPay(String openid,String no,String userName,Integer amount) throws WxPayException{ WxPayService wxPayService = WxPayConfiguration.getPayService(); EntPayRequest entPayRequest = new EntPayRequest(); entPayRequest.setOpenid(openid); entPayRequest.setPartnerTradeNo(no); entPayRequest.setCheckName("FORCE_CHECK"); entPayRequest.setReUserName(userName); entPayRequest.setAmount(amount); entPayRequest.setDescription("提现"); entPayRequest.setSpbillCreateIp("127.0.0.1"); wxPayService.getEntPayService().entPay(entPayRequest); }
Example #14
Source File: EntPayServiceImpl.java From weixin-java-tools with Apache License 2.0 | 4 votes |
public EntPayServiceImpl(WxPayService payService) { this.payService = payService; }
Example #15
Source File: WxPayConfiguration.java From mall4j with GNU Affero General Public License v3.0 | 4 votes |
@Bean public WxPayService wxMpPayService() { return getWxMpPayServiceByAppId(wxMp.getAppid()); }
Example #16
Source File: WxSendRedpackServiceImpl.java From fw-cloud-framework with MIT License | 4 votes |
@Override public R<Map<String, Object>> sendRedpack(PaySendRedpack paySendRedpack, WxPaySendRedpackRequest sendRedpackRequest) { Map<String, Object> returnMap = new HashMap<String, Object>(); // 设置会出现签名加密返回 returnMap.put(PayConstant.RETURN_PARAM_RETCODE, PayConstant.RETURN_VALUE_SUCCESS); returnMap.put("return_code", PayConstant.RETURN_VALUE_FAIL); returnMap.put("return_msg", "请求出现异常!"); boolean isCommonRedPack = paySendRedpack.getRedPackType().intValue() == 0; String resKey = paySendRedpack.getResKey(); String logPrefix = isCommonRedPack ? "【发放普通红包】" : "【发放裂变红包】"; try { log.info(logPrefix + "请求:" + sendRedpackRequest.toString()); WxPayService wxPayService = new WxPayServiceImpl(); wxPayService.setConfig(paySendRedpack.getWxPayConfig()); WxPaySendRedpackResult paySendRedpackResult = wxPayService.sendRedpack(sendRedpackRequest); paySendRedpack.setReturnCode(paySendRedpackResult.getReturnCode()); paySendRedpack.setReturnMsg(paySendRedpackResult.getReturnMsg()); paySendRedpack.setResultCode(paySendRedpackResult.getResultCode()); paySendRedpack.setErrCode(paySendRedpackResult.getErrCode()); paySendRedpack.setErrCodeDes(paySendRedpackResult.getErrCodeDes()); // 订单流水号 returnMap.put("send_order_id", paySendRedpack.getSendOrderId()); // 订单编号 returnMap.put("mch_order_no", paySendRedpack.getMchOrderNo()); returnMap.put("return_code", paySendRedpackResult.getReturnCode()); returnMap.put("return_msg", paySendRedpackResult.getReturnMsg()); returnMap.put("result_code", paySendRedpackResult.getResultCode()); returnMap.put("err_code", paySendRedpackResult.getErrCode()); returnMap.put("err_code_des", paySendRedpackResult.getErrCodeDes()); if (PayConstant.RETURN_VALUE_SUCCESS.equals(paySendRedpackResult.getReturnCode()) && PayConstant.RETURN_VALUE_SUCCESS.equals(paySendRedpackResult.getResultCode())) { paySendRedpack.setWxTotalAmount(paySendRedpackResult.getTotalAmount()); paySendRedpack.setSendListid(paySendRedpackResult.getSendListid()); paySendRedpack.setSendTime(paySendRedpackResult.getSendTime()); returnMap.put("total_amount", paySendRedpackResult.getTotalAmount()); returnMap.put("send_listid", paySendRedpackResult.getSendListid()); returnMap.put("send_time", paySendRedpackResult.getSendTime()); log.info(logPrefix + "响应:" + JSON.toJSONString(returnMap)); log.info(logPrefix + "结果:" + PayConstant.RETURN_VALUE_SUCCESS); } else { log.info(logPrefix + "响应:" + JSON.toJSONString(returnMap)); log.info(logPrefix + "结果:" + PayConstant.RETURN_VALUE_FAIL); } // 保存 发送明细数据入库 paySendRedpackRepository.saveAndFlush(paySendRedpack); return new R<Map<String, Object>>().data(PayUtil.makeRetData(returnMap, resKey)).success(); } catch (WxPayException e) { e.printStackTrace(); return new R<Map<String, Object>>().data(PayUtil.makeRetData(returnMap, resKey)).failure(logPrefix + "请求异常:" + e.toString()); } }
Example #17
Source File: WxPayAPI.java From springboot-seed with MIT License | 4 votes |
@Autowired public WxPayAPI(WxPayService wxService) { this.wxService = wxService; }
Example #18
Source File: WxPayConfiguration.java From mall4j with GNU Affero General Public License v3.0 | 4 votes |
@Bean public WxPayService wxMiniPayService() { return getWxMpPayServiceByAppId(wxMiniApp.getAppid()); }