支付常用的是微信支付和支付宝支付。二者正式版皆须应用注册和审核。微信人工审核,支付宝机器审核,快于微信。支付宝有沙箱环境,便于调试后正式使用,微信没有。沙箱环境调试会对应使用沙箱版支付宝APP。
1、微信支付:
https://pay.weixin.qq.com/wiki/doc/api/index.html
支付宝支付:
https://docs.open.alipay.com/catalog
支付宝开放平台:
https://open.alipay.com/platform/manageHome.htm
微信和支付宝支付参考:
https://ask.dcloud.net.cn/article/458
个人支付免签系统API版本:
https://github.com/yioMe/nodejs_wx_aipay_api
2、支付宝支付-沙箱环境:
https://openhome.alipay.com/platform/appDaily.htm
3、支付宝沙箱版APP登陆,用支付宝支付-沙箱环境中的沙箱账号的商家账号和登陆密码。
4、手机网站支付结果异步通知
https://docs.open.alipay.com/203/105286/
public class AlipayConfig {
public static String SERVER_ADDRESS = "";
/**
* 商户appid
*/
public static String APP_ID = "";
/**
* 商户私钥(pkcs8格式)
*/
public static String APP_PRIVATE_KEY = "";
/**
* 服务器异步通知页面路径
* 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
*/
public static String NOTIFY_URL = SERVER_ADDRESS + "payNotify";
/**
* 页面跳转同步通知页面路径
* 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址
*/
public static String RETURN_URL = SERVER_ADDRESS + "payReturn.html";
/**
* 请求网关地址(正式环境或沙箱环境)
*/
public static String GATEWAY_URL = "https://openapi.alipaydev.com/gateway.do";
/**
* 编码
*/
public static String CHARSET = "UTF-8";
/**
* 返回格式
*/
public static String FORMAT = "json";
/**
* 支付宝公钥
*/
public static String ALIPAY_PUBLIC_KEY = "";
/**
* 日志记录目录
*/
public static String LOG_PATH = System.getProperty("user.dir") + "log";
/**
* 标志类型
*/
public static String SIGN_TYPE = "RSA2";
/**
* 延时
*/
public static String TIMEOUT_EXPRESS = "2m";
/**
* 商品编码
*/
public static String PRODUCT_CODE = "FAST_INSTANT_TRADE_PAY";
/**
* 退出地址
*/
public static String QUIT_URL = SERVER_ADDRESS + "quit.html";
}
@GetMapping("order/pay")
@ResponseBody
public String pay(@RequestParam("orderNumber") String orderNumber, @RequestParam("subject") String subject, @RequestParam("amount") String amount,
@RequestParam("orderDescription") String orderDescription) {
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.GATEWAY_URL, AlipayConfig.APP_ID, AlipayConfig.APP_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGN_TYPE);
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
alipayRequest.setReturnUrl(AlipayConfig.RETURN_URL);
alipayRequest.setNotifyUrl(AlipayConfig.NOTIFY_URL);
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.setOutTradeNo(orderNumber);
model.setSubject(subject);
model.setTotalAmount(amount);
model.setBody(orderDescription);
model.setTimeoutExpress(AlipayConfig.TIMEOUT_EXPRESS);
model.setProductCode(AlipayConfig.PRODUCT_CODE);
model.setQuitUrl(AlipayConfig.QUIT_URL);
alipayRequest.setBizModel(model);
String form;
try {
AlipayTradePagePayResponse response = alipayClient.pageExecute(alipayRequest);
log.debug(response.getTradeNo());
form = alipayClient.pageExecute(alipayRequest).getBody();
log.debug(form);
return form;
} catch (AlipayApiException e) {
e.printStackTrace();
}
return null;
}
@PostMapping("payNotify")
@ResponseBody
public void notify(@RequestParam int clientId, @RequestParam String orderNumber, @RequestParam String aliPayId,
@RequestParam double amount, @RequestParam String orderDescription, @RequestParam String city) {
log.debug("支付宝异步通知");
}