use of com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse in project goodsKill by techa03.
the class AlipayRunner method tradePrecreate.
public String tradePrecreate(long seckillId) {
Seckill seckill = redisService.getSeckill(seckillId);
Goods goods = goodsMapper.selectById(seckill.getGoodsId());
// 需保证商户系统端不能重复,建议通过数据库sequence生成,
String outTradeNo = "tradeprecreate" + System.currentTimeMillis() + (long) (Math.random() * 10000000L);
// 1. 设置参数(全局只需设置一次)
Factory.setOptions(getOptions());
try {
// 2. 发起API调用(以创建当面付收款二维码为例)
AlipayTradePrecreateResponse response = Factory.Payment.FaceToFace().preCreate(goods.getName(), outTradeNo, String.valueOf(seckill.getPrice()));
// 3. 处理响应或异常
if (ResponseChecker.success(response)) {
String finalQrcodeImagePath = String.format(qrcodeImagePath + "/qr-%s.png", response.outTradeNo);
ZxingUtils.getQRCodeImge(response.qrCode, 256, finalQrcodeImagePath);
log.info("支付宝当面扫调用成功!");
return finalQrcodeImagePath.split("/")[finalQrcodeImagePath.split("/").length - 1];
} else {
log.error("调用失败,原因:" + response.msg + "," + response.subMsg);
}
} catch (Exception e) {
log.error("调用遭遇异常,原因:" + e.getMessage());
}
return null;
}
Aggregations