1. 程式人生 > >java支付寶掃碼支付,簡單生成二維碼方法

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:掃碼支付時的商品提示)