com.github.binarywang.wxpay.service.impl.WxPayServiceImpl Java Examples

The following examples show how to use com.github.binarywang.wxpay.service.impl.WxPayServiceImpl. 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: WxPayConfiguration.java    From mall4j with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #2
Source File: WxMaConfiguration.java    From charging_pile_cloud with MIT License 6 votes vote down vote up
@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 #3
Source File: ApiTestModule.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: WxPayConfiguration.java    From springboot-seed with MIT License 5 votes vote down vote up
@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 #5
Source File: WxSendRedpackServiceImpl.java    From fw-cloud-framework with MIT License 4 votes vote down vote up
@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());
	}
}