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;
}