韩国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提供的mid
        map.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 {
            //生成fgkey
            StringBuffer 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, "")) {
                // 定义HttpClient
                BufferedReader 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;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小的码农哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值