日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

企业付款到零钱(微信小程序提现,用户提现到零钱)

發布時間:2025/3/8 编程问答 26 如意码农
生活随笔 收集整理的這篇文章主要介紹了 企业付款到零钱(微信小程序提现,用户提现到零钱) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

pom 增加

    <dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId>
<version>3.2.0</version>
</dependency>

附上github https://github.com/Wechat-Group/WxJava/wiki

一、證書申請

企業付款需要用到p12證書,證書可以在商戶平臺的 賬戶平臺 - API安全 - API證書 中申請到。(注:需要升級一下)

二、WxPayConfig配置

將 com.github.binarywang.wxpay.service.WxPayService 作為Bean注入到項目中

實現代碼如下,具體作用讀者可引入pom后自行查看,binarywang作者的注釋非常詳細。有問題可留言討論

我在使用@Autowired 注解時無法注入 所以就注掉了 具體調用方法下面會貼上

/**
* 企業支付WxPayConfig配置
* @author hsw
*/
@Configuration
public class WxConfig { // @Autowired
// private WxMpProperties wxMpProperties; @Bean
public WxPayConfig wxPayConfig() {
// final List<WxMpProperties.MpConfig> configs = wxMpProperties.getConfigs();
WxPayConfig payConfig = new WxPayConfig();
// payConfig.setAppId(configs.get(1).getAppId());
// payConfig.setMchId(configs.get(1).getPayMchId());
// payConfig.setMchKey(configs.get(1).getPaySecretKey());
// payConfig.setNotifyUrl(configs.get(1).getPayResultUrl());
// payConfig.setKeyPath(configs.get(1).get);
payConfig.setTradeType("JSAPI");
payConfig.setSignType("MD5");
return payConfig;
} @Bean
public WxPayService wxPayService(WxPayConfig payConfig) {
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
return wxPayService;
}

3、API調用

 /**
* 進行微信提現操作 (企業付款至用戶零錢)
* @param openId
* @param amout 提現金額
* @param partnerTradeNo 單號
* @param desc 備注
*/
private EntPayResult getWithdrawal(String openId, BigDecimal amout,String partnerTradeNo, String desc, HttpServletRequest request){
final List<WxMpProperties.MpConfig> configs = wxMpProperties.getConfigs();
EntPayRequest entPayRequest = new EntPayRequest();
entPayRequest.setAppid(configs.get(1).getAppId());
entPayRequest.setMchId(configs.get(1).getPayMchId());
entPayRequest.setPartnerTradeNo(partnerTradeNo);
entPayRequest.setOpenid(openId);
entPayRequest.setCheckName("NO_CHECK");
entPayRequest.setAmount(Integer.valueOf(amout.multiply(new BigDecimal(100)).setScale(0, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()));
entPayRequest.setDescription(desc);
entPayRequest.setSpbillCreateIp(IpUtils.getIpAddr(request));
EntPayResult entPayResult = null;
try {
//此處調用=============================================================
// 通過Java配置來實例化Spring容器
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WxConfig.class);
// 在Spring容器中獲取Bean對象
WxConfig wxConfig = context.getBean(WxConfig.class);
WxPayService wxPayService = wxConfig.wxPayService(wxConfig.wxPayConfig());
entPayResult = wxPayService.getEntPayService().entPay(entPayRequest);
log.info("entPayResult : " + entPayResult);
System.out.println(entPayResult);
} catch (WxPayException e) {
log.error("付款失敗,返回報文" + e);
throw new ApiException(e.getCustomErrorMsg());
}
return entPayResult;
}
 

總結

以上是生活随笔為你收集整理的企业付款到零钱(微信小程序提现,用户提现到零钱)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。