韩国ICB支付
ICB支付是代理了韓國的支付寶與微信支付,通過ICB封裝好的統一支付接口,根據參數不同可分別調取支付寶支付和微信
1.支付url
? 測試環境 :https://onlinetest.funpay.co.kr/payment/payment.icb ? 線上環境 :https://online.funpay.co.kr/payment/payment.icb首先配置支付所需的參數
Mandatory為0是必填項?,其中statusurl為后臺的回調地址,支付成功返回resmgs為success,returnurl 為支付完成后跳轉的頁面,其他的參數可查看上圖所示注解。
后臺拼接參數代碼實例
/*** 拼接icb支付所需的參數** @param payInfo* @return*/public Map<String, Object> payParameter(PayInfoDto payInfo) {Map<String, Object> map = new HashMap();map.put("ver", "100");//icb提供的midmap.put("mid", "************");//項目名稱map.put("mname", "**");//支付方式S000支付寶 S001微信map.put("servicetype", "S000");//項目訂單號map.put("refno", payInfo.getPayNo());//貨幣類型map.put("reqcur", "CNY");//支付金額map.put("reqamt", payInfo.getPayAmount());//買家名稱map.put("buyername", payInfo.getUserId());//購買產品名稱map.put("product", payInfo.getBody());//后臺回調地址map.put("statusurl", payInfo.getApiNoticeUrl());//支付方式map.put("reqtype", "M");//支付類型map.put("restype", "JSON");//支付完跳轉頁面map.put("returnurl", "https://baidu.com");map.put("refer_url", "https://baidu.com");//商品信息map.put("trade_information", "{\"business_type\":\"4\",\"goods_info\":pencial^1|eraiser^1\",\"total_quantity\":2}");//進行加密生成fgkey參數MessageDigest messageDigest = null;try {//生成fgkeyStringBuffer buffer = new StringBuffer();Iterator iters = map.entrySet().iterator();while (iters.hasNext()) {Map.Entry entry = (Map.Entry) iters.next();if (buffer.toString().length() == 0) {buffer.append(entry.getKey() + "=" + entry.getValue());continue;}buffer.append("&" + entry.getKey() + "=" + entry.getValue());}char[] chars = buffer.toString().toCharArray();Arrays.sort(chars);String A = String.valueOf(chars);String B = "icb提供的密鑰" + "?" + A;messageDigest = MessageDigest.getInstance("SHA-256");messageDigest.update(B.getBytes("UTF-8"));} catch (NoSuchAlgorithmException e) {e.printStackTrace();} catch (UnsupportedEncodingException e) {e.printStackTrace();}String C = Sha256Util.bytes2Hex(messageDigest.digest());String s = C.toUpperCase();map.put("fgkey", s);Map clint = HttpClint(map, "https://online.funpay.co.kr/payment/payment.icb");return clint;}?返回的map中前端將resmgs字段拼接到?https://intlmapi.alipay.com/gateway.do?之后即可喚起支付寶或微信的支付頁面,代碼中使用的工具類如下。
public class Sha256Util {/*** byte數組轉換為16進制字符串** @param bts* 數據源* @return 16進制字符串*/public static String bytes2Hex(byte[] bts) {String des = "";String tmp = null;for (int i = 0; i < bts.length; i++) {tmp = (Integer.toHexString(bts[i] & 0xFF));if (tmp.length() == 1) {des += "0";}des += tmp;}return des;}public static HashCode sha256(final String x) {Preconditions.checkNotNull(x);final Charset charset = Charsets.UTF_8;final HashFunction hashFunction = Hashing.sha256();return hashFunction.newHasher().putString(x, charset).hash();} } /*** 進行請求** @param params, url* @return*/public Map HttpClint(Map params, String url) {Map map = new HashMap();try {if (null != url && !Objects.equals(url, "")) {// 定義HttpClientBufferedReader in = null;HttpClient client = new DefaultHttpClient();// 實例化HTTP方法HttpPost request = new HttpPost();request.setURI(new URI(url));//設置參數List<NameValuePair> nvps = new ArrayList<NameValuePair>();for (Iterator iter = params.keySet().iterator(); iter.hasNext(); ) {String name = (String) iter.next();String value = String.valueOf(params.get(name));nvps.add(new BasicNameValuePair(name, value));}request.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));HttpResponse response = client.execute(request);String responseBody = EntityUtils.toString(response.getEntity());Map map1 = JSON.parseObject(responseBody, Map.class);return map1; }總結
- 上一篇: cadence logic 库说明
- 下一篇: 115道Java面试题及答案分享,jav