支付宝APP支付服务端加签

添加支付宝SDK1.5依赖:

<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<dependency>
    <groupId>com.alipay.sdk</groupId>
    <artifactId>alipay-sdk-java</artifactId>
    <version>3.0.0</version>
</dependency>

支付宝加签示例:

//实例化客户端
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY, "RSA2");
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody("我是测试数据");
model.setSubject("App支付测试Java");
model.setOutTradeNo(outtradeno);
model.setTimeoutExpress("30m");
model.setTotalAmount("0.01");
model.setProductCode("QUICK_MSECURITY_PAY");
request.setBizModel(model);
request.setNotifyUrl("商户外网可以访问的异步地址");
try {
        //这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        System.out.println(response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。
    } catch (AlipayApiException e) {
        e.printStackTrace();
}

返回示例:

alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016091908609577&biz_content=%7B%22out_trade_no%22%3A%
2220180416YXTD00000078541%22%2C%22total_amount%22%3A0.01%2C%22quit_url%22%3A%22http%3A%2F%2Fbaidu.com%22
%2C%22subject%22%3A%22%E4%BF%A1%E8%B4%B7%E5%91%98%E9%87%91%E5%B8%81%E5%85%85%E5%80%BC%22%2C%22product_code
%22%3A%22QUICK_MSECURITY_PAY%22%2C%22seller_id%22%3A%222088821142121972%22%7D&charset=utf-8&format=json&
method=alipay.trade.app.pay¬ify_url=http%3A%2F%2F114.215.241.69%2Ftrade%2Fnotify&sign=HGbGWqOqI22us2vGYWs
Bae3wPeu8XhvMjjvvCknS4YJdsXTPrixrAtKSoM2tlizz%2FaFIXepEqgsIn0TR01hYShs40nJyK2zBklKJ4JtHKU1EX2R0I7KGdR4rfX
vy6zA1L7EbavCPdwnLg0hnzCTFqN6Or9L3ngQOy9myqA%2BpRu6mrDq2gvAFaLuPbSf9RhQf4z6rjV0ZvqDaSqDffjH2ThH7hYd79qYSi
ezn%2BjlqSkujsO3jZJ1nfFtUVi9RuU%2FHOpD1Z2qq5Jxxlmw2mMu06YKja94Kbsj9m5ATTJ2Ww8ueC90YgtoB03NagCNbU8AxAL3246
JQbMh1FkMHhZMrnQ%3D%3D&sign_type=RSA2×tamp=2018-04-17+09%3A48%3A35&version=1.0

提示:该返回示例不可用

返回的response.getBody直接返回给客户端,让客户端用支付宝SDK调起支付宝客户端(未安装支付宝用户将调起支付宝H5页面)即可

阅读更多
个人分类: Java
上一篇Docker配置镜像加速器重启Docker服务失败
下一篇react新增一行数据删除一行数据
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭