Map<String, String> map = new HashMap<>(1);
try {
PreRechargeOrders preRechargeOrders = preRechargeOrdersDao.queryById(id);
PreUsers preUsers = preUsersDao.queryById(preRechargeOrders.getUserId());
String productDesc = "xx充值";
String timeExpire = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(new Date().getTime() + 1000 * 60 * 3);
int money_fen = changY2F(preRechargeOrders.getPrice().floatValue());
Config config =
new RSAPublicKeyConfig.Builder()
.merchantId(mchId) //微信支付的商户号
.privateKeyFromPath(keyPath) // 商户API证书私钥的存放路径
.publicKeyFromPath(pub_key) //微信支付公钥的存放路径
.publicKeyId(publicKey) //微信支付公钥ID
.merchantSerialNumber(apiKey) //商户API证书序列号
.apiV3Key(apiKey3) //APIv3密钥
.build();
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest prepayRequest = new com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest();
Amount amount = new Amount();
amount.setTotal(money_fen);
prepayRequest.setAmount(amount);
prepayRequest.setAppid(appId);
prepayRequest.setMchid(mchId);
prepayRequest.setDescription(productDesc);
prepayRequest.setOutTradeNo(preRechargeOrders.getRechargeNo());
prepayRequest.setTimeExpire(timeExpire);
prepayRequest.setAttach("xx充值");
prepayRequest.setNotifyUrl(domain.concat("/recharge/taocanRecharge"));
Payer payer = new Payer();
payer.setOpenid(preUsers.getOpenId());
prepayRequest.setPayer(payer);
SettleInfo settleInfo = new SettleInfo();
settleInfo.setProfitSharing(false);
prepayRequest.setSettleInfo(settleInfo);
PrepayWithRequestPaymentResponse prepayWithRequestPaymentResponse = service.prepayWithRequestPayment(prepayRequest);
map.put("code", "200");
map.put("appId", prepayWithRequestPaymentResponse.getAppId());
map.put("timeStamp", prepayWithRequestPaymentResponse.getTimeStamp());
map.put("nonceStr", prepayWithRequestPaymentResponse.getNonceStr());
map.put("package", prepayWithRequestPaymentResponse.getPackageVal());
map.put("signType", prepayWithRequestPaymentResponse.getSignType());
map.put("paySign", prepayWithRequestPaymentResponse.getPaySign());
} catch (Exception e) {
e.printStackTrace();
}
引入jar
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId>
<version>0.2.17</version>
</dependency>
回调接入:
public Map<String, String> rechargeNotify(HttpServletRequest request, HttpServletResponse response) {
Map<String, String> map = new HashMap<>(12);
String timestamp = request.getHeader("Wechatpay-Timestamp");
String nonce = request.getHeader("Wechatpay-Nonce");
String serialNo = request.getHeader("Wechatpay-Serial");
String signature = request.getHeader("Wechatpay-Signature");
log.info("timestamp:{} nonce:{} serialNo:{} signature:{}" + timestamp + nonce + serialNo + signature);
String result = HttpKit.readData(request);
log.info("支付通知密文 {}" + result);
NotificationConfig config = new RSAPublicKeyNotificationConfig.Builder()
.publicKeyFromPath(pub_key)
.publicKeyId(publicKey)
.apiV3Key(apiKey3)
.build();
NotificationParser parser = new NotificationParser(config);
RequestParam requestParam = new RequestParam.Builder()
.serialNumber(publicKey)
.nonce(nonce)
.signature(signature)
.timestamp(timestamp)
.body(result)
.build();
Transaction transaction = parser.parse(requestParam, Transaction.class);
JSONObject jsonObject = JSONUtil.parseObj(transaction);
log.info("---解析数据:" + jsonObject);
}

被折叠的 条评论
为什么被折叠?



