java支付宝扫码支付,简单生成二维码方法

支付宝扫码支付
首先申请 appid、app_private_key,publicKey,
直接上代码:
方式一:可以禁用支付通道(disable_pay_channels)
public static void main(String[] args) throws AlipayApiException {
AlipayClient alipayClient = new DefaultAlipayClient(SERVERURL,APP_ID,APP_PRIVATE_KEY,FORMAT,CHARSET,ALIPAY_PUBLIC_KEY,SIGNTYPE);
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
request.setBizContent("{" +
““out_trade_no”:“20180320010101001”,” +
““total_amount”:88.88,” +
““subject”:“Iphone6 16G””+
/"“seller_id”:“2018091961456482”," +
““discountable_amount”:8.88,” +
““goods_detail”:[{” +
““goods_id”:“apple-01”,” +
““goods_name”:“ipad”,” +
““quantity”:1,” +
““price”:2000,” +
““goods_category”:“34543238”,” +
““categories_tree”:“124868003|126232002|126252004”,” +
““body”:“特价手机”,” +
““show_url”:“http://www.alipay.com/xxx.jpg”” +
“}],” +
““body”:“Iphone6 16G”,” +
““operator_id”:“yx_001”,” +
““store_id”:“NJ_001”,” +
““disable_pay_channels”:“pcredit,moneyFund,debitCardExpress”,” +
““enable_pay_channels”:“pcredit,moneyFund,debitCardExpress”,” +
““terminal_id”:“NJ_T_001”,” +
““extend_params”:{” +
““sys_service_provider_id”:“2088511833207846”,” +
““industry_reflux_info”:”{\\\“scene_code\\\”:\\\“metro_tradeorder\\\”,\\\“channel\\\”:\\\“xxxx\\\”,\\\“scene_data\\\”:{\\\“asset_name\\\”:\\\“ALIPAY\\\”}}"," +
““card_type”:“S0JP0000"” +
“},” +
““timeout_express”:“90m”,” +
““settle_info”:{” +
““settle_detail_infos”:[{” +
““trans_in_type”:“cardSerialNo”,” +
““trans_in”:“A0001”,” +
““summary_dimension”:“A0001”,” +
““settle_entity_id”:“2088xxxxx;ST_0001”,” +
““settle_entity_type”:“SecondMerchant、Store”,” +
““amount”:0.1” +
“}]},” +
““business_params”:”{\“data\”:\“123\”}”," +
““qr_code_timeout_express”:“90m”” +
/
" }");
AlipayTradePrecreateResponse response = alipayClient.execute(request);
if(response.isSuccess()){
System.out.println(“调用成功”);
String qrCode = response.getQrCode();
System.out.println("------qrCode-------"+qrCode);
// 需要修改为运行机器上的路径
String filePath = String.format("/Users/sudo/Desktop/qr- %s.png",response.getOutTradeNo());
//将生成的二维码存放到指定路径
ZxingUtils.getQRCodeImge(response.getQrCode(), 256, filePath);
} else {
System.out.println(“调用失败”);
}
注:1.实际上,支付宝生成的二维码图片我们可以不用,只用它生成的一串二维码字符串qrCode,前端可以用js来把字符串还原成二维码。这样我们也不必为保存二维码图片的空间苦恼
2.发送请求时,我们可以根据自己需要来设置参数,有三个是必须参数(out_trade_no:订单号,total_amount:总价,subject:扫码支付时的商品提示)

你可能感兴趣的:(java支付宝扫码支付,简单生成二维码方法)