Java实现⽀付宝⼩程序⽀付功能
本⽂主要是Java实现⽀付宝⼩程序⽀付功能:
// 实例化客户端
AlipayClient alipayClient = new DefaultAlipayClient("openapi.alipay/gateway.do",
"json", "UTF-8", Property("ALIPAY_PUBLICKEY"), "RSA2");
// 实例化具体API对应的request类,类名称和接⼝名称对应,当前调⽤接⼝名称:ade.app.pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
// SDK已经封装掉了公共参数,这⾥只需要传⼊业务参数。以下⽅法为sdk的model⼊参⽅式(model和biz_content同时存在的情况下取biz_content)。            AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
if (consumptionType == 0) {
model.setBody("押⾦缴纳");
model.setSubject("⽤户缴纳押⾦");
} else {
model.setBody("充值");
model.setSubject("⽤户充值");
}
model.setOutTradeNo(orderNo);
model.setTimeoutExpress("30m");
model.setTotalAmount(consumptionAmount + "");
model.setProductCode("QUICK_MSECURITY_PAY");
request.setBizModel(model);
request.setNotifyUrl("www.hopefull/smallBed/transaction/alipayNotify/" + orderNo);
try {
// 这⾥和普通的接⼝调⽤不同,使⽤的是sdkExecute
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
System.out.Body());// 就是orderString
// 可以直接给客户端请求,⽆需再做处理。
dto.Body());
} catch (AlipayApiException e) {
e.printStackTrace();
}
/**
* ⽀付宝异步回调⽅法
* @author Mark
* @throws AlipayApiException
* @throws IOException
*/
@RequestMapping("/alipayNotify/{batchNo}")
public void alipayNotify(HttpServletRequest request, HttpServletResponse response, @PathVariable String batchNo)
throws Exception {
logger.info("进⼊⽀付宝⽀付回调");
logger.info("⽀付编号为:" + batchNo);
Map<String, String[]> requestParams = ParameterMap();
logger.info("⽀付宝回调参数:" + String());
Map<String, String> params = new LinkedHashMap<String, String>();
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
String name = (String) ();
String[] values = (name);
String valueStr = "";
有趣的java小程序
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
}
params.put(name, valueStr);
}
logger.info("⽀付宝回调参数:" + String());
String status = ("trade_status");
Boolean signVerified = AlipaySignature.rsaCheckV1(params, Property("ALIPAY_PUBLICKEY"),
"UTF-8","RSA2");
logger.info("验证签名结果:" + signVerified);
if (signVerified) {
logger.info("status" + status);
logger.info("status" + status);
if (org.apachemons.lang.StringUtils.LowerCase(), "trade_success")) {
int result = transactionService.updatePayStatusByOrderNo(batchNo);
if (result > 0) {
Transaction t = TransactionByOrderNo(batchNo);
if (t.getAfterSale() == 0) {
memberService.updateMemberDeposits(1, t.getConsumptionAmount(), t.getMemberId());
} else {
memberService.ConsumptionAmount(), t.getMemberId());                }
Transaction ts = MemberId());
transactionService.ConsumptionAmount(), t.getId());
}
try {
} catch (IOException e) {
<(Message(e));
}
} else if (org.apachemons.lang.StringUtils.LowerCase(), "trade_finished")) {
try {
} catch (IOException e) {
<(Message(e));
}
}
} else {
<("参数验证失败");
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。