支付寶掃碼須要開通特定權限,拼接參數有些許不一樣,頁面上的二維碼若是是內嵌的就讓H5本身去生成,訂單和請求字符串服務端生成:ui
Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("service",PayPropertiesUtils.getString("alipay.scanCodePay.service")); paramMap.put("partner",PayPropertiesUtils.getString("alipay.scanCodePay.partner")); paramMap.put("_input_charset",PayPropertiesUtils.getString("alipay.inputCharset")); paramMap.put("notify_url",PayPropertiesUtils.getString("alipay.scanCodePay.notifyUrl")); if(StringUtils.isBlank(payExtendVo.getReturnUrl())) { if(!StringUtils.isBlank(paymentTypeEnum.getReturnUrlPropName())) { paramMap.put("return_url",PayPropertiesUtils.getString(paymentTypeEnum.getReturnUrlPropName())); } } else { paramMap.put("return_url",payExtendVo.getReturnUrl()); } paramMap.put("out_trade_no",payExtendVo.getOrderId()); paramMap.put("subject", GlobalConstants.PAY_PRODUCT_NAME); paramMap.put("payment_type", PayPropertiesUtils.getString("alipay.scanCodePay.paymentType")); paramMap.put("total_fee", String.valueOf(payExtendVo.getPayAmount())); paramMap.put("seller_id", PayPropertiesUtils.getString("alipay.scanCodePay.partner")); paramMap.put("seller_email", PayPropertiesUtils.getString("alipay.scanCodePay.sellerEmail")); paramMap.put("body", GlobalConstants.PAY_PRODUCT_NAME); //show_url 收銀臺頁面上,商品展現的超連接。可空 //paymethod 取值範圍: creditPay(信用支付) directPay(餘額支付) 若是不設置,默認識別爲餘額支付。 //enable_paymethod 支付渠道 用於控制收銀臺支付渠道顯示,該值的取值範圍請參見支付渠道。 可支持多種支付渠道顯示,以「^」分隔。可空 //anti_phishing_key 防釣魚時間戳 //exter_invoke_ip 防釣魚保護時必填寫 //extra_common_param 公用回傳參數 可控 //token 若是開通了快捷登陸產品,則須要填寫;若是沒有開通,則爲空。 //need_buyer_realnamed 是否須要買家實名認證 T表示須要買家實名認證; 不傳或者傳其它值表示不須要買家實名認證。可空 //hb_fq_param 花唄分期參數 paramMap.put("it_b_pay", PayPropertiesUtils.getString("alipay.scanCodePay.itBPay")); paramMap.put("qr_pay_mode", PayPropertiesUtils.getString("alipay.scanCodePay.qrPayMode")); //商戶自定二維碼寬度 當qr_pay_mode=4時,該參數生效。 if(StringUtils.isNotBlank(payExtendVo.getQrcodeWidth())) { paramMap.put("qrcode_width",payExtendVo.getQrcodeWidth()); } paramMap.put("goods_type",PayPropertiesUtils.getString("alipay.scanCodePay.goodsType")); logger.info("alipayScanCodePayService----thridPartyPayCall-----"); //去除空值 Map<String,String> signMap = AlipayCore.paraAppFilter(paramMap); //生成簽名 String sign = Signature.buildRequestMysign(signMap,PayPropertiesUtils.getString("alipay.scanCodePay.signType"), PayPropertiesUtils.getString("alipay.scanCodePay.md5Key")); signMap.put("sign",sign); logger.info("alipayScanCodePayService----thridPartyPayCall-----sign="+sign); //獲取業務參數串 String payReqStr = PayPropertiesUtils.getString("alipay.scanCodePay.requestUrl") + AlipayCore.createLinkString(signMap); logger.info("alipayScanCodePayService----thridPartyPayCall-----payReqStr=" + payReqStr); Map returnMap = new HashMap(); returnMap.put("scanCodeUrl",payReqStr); returnMap.put("orderId",payExtendVo.getOrderId()); returnMap.put("payAmount",tradeLog.getPayAmount()); returnMap.put("income",tradeLog.getIncome()); returnMap.put("rewardFanpiao",tradeLog.getRewardFanpiao()); returnMap.put("incomeAmount",tradeLog.getIncomeAmount()); resultBean.setData(returnMap); //存庫
支付寶的回調跟手機端回調差很少:url
String tradeStatus = String.valueOf(thridPartyNotifyVo.getAlipayTradeStatus()); try { Map<String, String> checkParamsMap = new HashMap<String,String>(); Map requestParams = thridPartyNotifyVo.getAliPayRequestParamsMap(); for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); String[] values = (String[]) requestParams.get(name); String valueStr = ""; for (int i = 0; i < values.length; i++) { valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ","; } //亂碼解決,這段代碼在出現亂碼時使用。若是mysign和sign不相等也能夠使用這段代碼轉化 //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk"); checkParamsMap.put(name, valueStr); } if (AlipayNotify.verify(checkParamsMap,PayPropertiesUtils.getString("alipay.scanCodePay.signType"),PayPropertiesUtils.getString("alipay.scanCodePay.md5Key"))) { //驗證響應請求正確 if(!"TRADE_FINISHED".equals(tradeStatus) && !"TRADE_SUCCESS".equals(tradeStatus)) { //支付失敗 resultBean = new ResultBean(ResultCode.PayAlipayNotifyIsPayFail.get_code(),ResultCode.PayAlipayNotifyIsPayFail.getMsg()+";返回誤碼:"+tradeStatus, NOTFIY_EXCEPTION_IS_HANDLER); } } else { resultBean = new ResultBean(ResultCode.UNSUCCESS.get_code(),ResultCode.PayAlipayNotifyIsNotValidUrl.getMsg()+";返回碼:"+tradeStatus, NOTFIY_EXCEPTION_IS_NOT_HANDLER); } //更餘額
最後別忘了返回支付寶一個success,要不他一直髮code