1. 程式人生 > 實用技巧 >威富通第三方掃碼支付

威富通第三方掃碼支付

下單API文件:https://open.swiftpass.cn/openapi/doc?index_1=187&index_2=1&chapter_1=2328&chapter_2=2329

基本流程:1.前臺攜帶基本資訊金額等。調取後臺與下單並返回一個支付二維碼

     2.成功支付回撥設定好的介面,完成下單操作

1.獲取二維碼圖片地址連結

/**
 * <一句話功能簡述>
 * <功能詳細描述>測試支付
 *
 * @author Administrator
 * @version [版本號, 2018-2-01]
 * @see [相關類/方法]
 * 
@since [產品/模組版本] */ public class PayUtils extends HttpServlet { private final static String sign_type = "";加密方式 private static final String notify_url = "";//支付成功後回撥地址 private static final String mch_id = "";//商戶號 private static final String req_url = "";//請求威富通地址 private static final String swiftpassKey = "";//加密鹽
public static Map pay(int money, String orderId) throws IOException { SortedMap<String, String> map = new TreeMap<String, String>(); map.put("mch_id", mch_id); map.put("service", "unified.trade.native"); map.put("nonce_str", String.valueOf(System.currentTimeMillis())); map.put(
"out_trade_no", orderId); map.put("body", );//在支付頁面會顯示的資訊 map.put("total_fee", String.valueOf(money * 100)); map.put("mch_create_ip", InetAddress.getLocalHost().getHostName()); map.put("notify_url", notify_url); map.put("nonce_str", String.valueOf(System.currentTimeMillis())); map.put("sign_type", sign_type); //map.put("device_info", "pos001");//終端裝置號,商戶自定義。特別說明:對於QQ錢包支付,此引數必傳,否則會報錯。 Map<String, String> params = SignUtils.paraFilter(map); StringBuilder buf = new StringBuilder((params.size() + 1) * 10); SignUtils.buildPayParams(buf, params, false); String preStr = buf.toString(); String sign = MD5.sign(preStr, "&key=" + swiftpassKey, "utf-8"); map.put("sign", sign); System.out.println("請求xml:" + XmlUtils.toXml(map)); String reqUrl = req_url; System.out.println("reqUrl:" + reqUrl); System.out.println("reqParams:" + XmlUtils.parseXML(map)); CloseableHttpResponse response = null; CloseableHttpClient client = null; try { HttpPost httpPost = new HttpPost(reqUrl); StringEntity entityParams = new StringEntity(XmlUtils.parseXML(map), "utf-8"); httpPost.setEntity(entityParams); client = HttpClients.createDefault(); response = client.execute(httpPost); if (response != null && response.getEntity() != null) { Map<String, String> resultMap = XmlUtils.toMap(EntityUtils.toByteArray(response.getEntity()), "utf-8"); return resultMap; } } catch (Exception e) { e.printStackTrace(); } finally { if (response != null) { response.close(); } if (client != null) { client.close(); } } return null; } }

處理返回結果

    JSONObject json = (JSONObject) JSONObject.parse(res);

        if (json != null && json.size() > 0) {
            result.setResult(new Result(true, json.get("data")));
            return result;
        }
        result.setResult(new Result(false, "url獲取失敗"));

2.回撥介面處理

/**
     * @description:威富通支付後回撥介面
     * @author:hdh
     * @date:2020/7/24 15:17
     **/
    @RequestMapping("")
    @ResponseBody
    public String confirmPay(@RequestBody Map map) {
return "success";
    }

3.開發Demo和utils下載地址

https://open.swiftpass.cn/openapi/doc?index_1=187&index_2=1&chapter_1=2337&chapter_2=2340