web端网站接入支付宝支付过程

1、在支付宝开放平台(https://open.alipay.com/platform/home.htm)申请对应的功能

web端网站接入支付宝支付过程

文章插图
 
找到页或者移动应用列表
web端网站接入支付宝支付过程

文章插图
 
你可以看到你已申请的应用
点击进入应用详情增加功能:
web端网站接入支付宝支付过程

文章插图
 
2、在自己的JAVAweb应用里引入对应的jar包<!--阿里支付SDK--><dependency><groupId>com.alipay.sdk</groupId><artifactId>alipay-sdk-java</artifactId><version>4.3.0.ALL</version></dependency>3、支付宝相关配置信息可根据自己的情况配置相关的内容,下面只作为相关示意
package com.fast.tpp.dto;public class AlipayConfig {/*** 签约的支付宝账号对应的支付宝唯一用户号,以2088开头的16位纯数字组成*/public static final String PID = "xx";/*** 正式环境请求地址*/public static String ALIPAY_URL = "https://openapi.alipay.com/gateway.do";/*** 支付宝分配给开发者的应用ID**/public static String App_ID = "xx";/*** 仅支持JSON*/public static String FORMAT = "JSON";/*** 请求使用的编码格式*/public static String CHARSET = "utf-8";/*** 商户生成签名字符串所使用的签名算法类型*/public static String SIGN_TYPE = "RSA2";/*** 支付宝公钥*/public static String ALIPAY_PUBLIC_KEY =xx";/*** 商户私钥*/public static String PRIVATE_KEY =xx";/*** 回调地址*/public static String CALLBACK_URL = "xx";/*** web支付跳转地址*/public static String WEB_RETURN_URL = "xx";}4、初始化阿里支付相关配置,只贴部分代码作参考@Service@Log4j2public class AlipaySaoImpl implements AlipaySao {@Autowiredprivate redisService redisService;// 实例化客户端AlipayClient alipayClient;public AlipaySaoImpl(){// 实例化客户端alipayClient = new DefaultAlipayClient(AlipayConfig.ALIPAY_URL,AlipayConfig.APP_ID,AlipayConfig.PRIVATE_KEY,AlipayConfig.FORMAT,AlipayConfig.CHARSET,AlipayConfig.ALIPAY_PUBLIC_KEY,AlipayConfig.SIGN_TYPE);}5、web支付相关方法代码package com.fast.tpp.dto;import lombok.Getter;import lombok.Setter;import lombok.ToString;@Setter@Getter@ToStringpublic class AlipayWebPayDTO{/*** 商户订单号,必填**/private String out_trade_no;/*** 订单名称,必填*/private String subject;/*** 付款金额,必填* 根据支付宝接口协议,必须使用下划线*/private String total_amount;/*** 商品描述,可空*/private String body;/*** 超时时间参数*/private String timeout_express= "5m";/*** 产品编号*/private String product_code= "FAST_INSTANT_TRADE_PAY";} /*** web支付接口* @param alipayBean* @return* @throws AlipayApiException*/@Overridepublic String webPagePay(AlipayWebPayDTO alipayBean) throws AlipayApiException {// 2、设置请求参数AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();// 页面跳转同步通知页面路径alipayRequest.setReturnUrl(AlipayConfig.WEB_RETURN_URL);// 服务器异步通知页面路径alipayRequest.setNotifyUrl(AlipayConfig.CALLBACK_URL);// 封装参数alipayRequest.setBizContent(JSON.toJSONString(alipayBean));// 3、请求支付宝进行付款,并获取支付结果String result = alipayClient.pageExecute(alipayRequest).getBody();// 返回付款信息return result;}6、最终返回给客户端的result值为,里面是一个form,页面拿到后会自动跳转到支付宝的订单支付页面{ "code": "00", "msg": "请求成功!", "data": {"orderString": "<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=G0jsaTORXtfF1VkQEK77qu%2BnYRU1YhCNQMFiWNNBUbYgQz8pxGRGVcnzbIXWkgWawV3AXco%2BJkFEemhV7qK2ALIn6uVziNklV6Folqb6OyVnsdKdCfHbID%2Bz79M1ngpyWsWvxXoAUN6Kuib5qkurDPQfMo4HWF4fxmLF70cFkQNeHxg577ByHS0%2Borv%2BzJ%2FwqehZZqOB1JQ0jzserODf2PGieoE5PCDnIYuXMZFqJqlCRUDc1IN3h9Usez8QJhLWepcFDsDR8tXiHrMmge9onHAl9bpLUtyOuVe4TCMU%2BLgMH21NUpeKJdXgQpnQxA8DoUuU0lRTmvPEp6EyXAmE%2FQ%3D%3D&return_url=http%3A%2F%2Fwww.moyou520.com%2Fdist%2Fhtml%2Fpay%2Fresult.html¬ify_url=http%3A%2F%2Fadmin.moyou520.com%2Fmoyou%2Fapp%2Ftrans%2FalipayNotice.do&version=1.0&app_id=2019081066129967&sign_type=RSA2×tamp=2020-02-17+15%3A58%3A24&alipay_sdk=alipay-sdk-java-4.3.0.ALL&format=JSON">n<input type="hidden" name="biz_content" value=https://www.isolves.com/it/cxkf/bk/2020-03-16/"{"body":"购买[年度VIP]","out_trade_no":"20200217155823617499935","product_code":"FAST_INSTANT_TRADE_PAY","subject":"默友APP","timeout_express":"5m","total_amount":"0.0"}">n


推荐阅读