赞
踩
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId>
<version>0.2.10</version>
</dependency>
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.RSAConfig; import com.wechat.pay.java.service.payments.jsapi.JsapiService; import com.wechat.pay.java.service.payments.jsapi.model.Amount; import com.wechat.pay.java.service.payments.jsapi.model.Payer; import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest; import com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class WeiXinPay { //@Value("${weixin.appId}") private String weixinAppId; /** 商户号 */ public static String merchantId = ""; /** 商户API私钥路径 */ public static String privateKeyPath = ""; /** 商户证书序列号 例如-证书序列号:54776TTTF8F77EXXX3641FAB5F940FII11C65347*/ public static String merchantSerialNumber = ""; /** 微信支付平台证书路径 例如:wechatpay_3A4AF69999DF01F39BB08C21C1C29B6AA17C074N.pem*/ public static String wechatPayCertificatePath = ""; /** 微信支付 APIv3 密钥 */ public static String apiV3Key = ""; public String createPreparePay() { Config config = new RSAConfig.Builder() //商户ID .merchantId(merchantId) //商户私钥文件(apiclient_key.pem)路径 .privateKeyFromPath(privateKeyPath) //商户证书序列号 例如-证书序列号:54776TTTF8F77EXXX3641FAB5F940FII11C65347 .merchantSerialNumber(merchantSerialNumber) //微信支付平台证书文件路径 例如:wechatpay_3A4AF69999DF01F39BB08C21C1C29B6AA17C074N.pem .wechatPayCertificatesFromPath(wechatPayCertificatePath) .build(); JsapiService service = new JsapiService.Builder().config(config).build(); PrepayRequest request = new PrepayRequest(); Amount amount = new Amount(); amount.setTotal(100); request.setAmount(amount); request.setAppid("wxa9d9651ae******"); request.setMchid("190000****"); request.setDescription("测试商品标题"); request.setNotifyUrl("https://notify_url"); request.setOutTradeNo("out_trade_no_001"); Payer payer = new Payer(); payer.setOpenid("oLTPCuN5a-nBD4rAL_fa********"); request.setPayer(payer); PrepayResponse response = service.prepay(request); System.out.println(response.getPrepayId()); return ""; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。