Android支付宝支付和微信支付

2018-02-27  本文已影响33人  猪爸爸Hulk
支付宝请求参数拼接
private String getOrderAli() {
        Gson gson = new Gson();
        String content = gson.toJson(new Info());
        String[] keys = {"app_id", "biz_content", "charset", "format", "method", "notify_url", "sign_type", "timestamp", "version"};
        String[] values = {"201888888888", content, "utf-8", "json", "alipay.trade.app.pay", "回调地址", "RSA2", "2018-02-06 17:00:31", "1.0"};
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < keys.length; i++) {
            sb.append(keys[i]);
            sb.append("=");
            sb.append(values[i]);
            if (i != keys.length - 1) {
                sb.append("&");
            }
        }
        String result = sb.toString();
        String sign = SignUtils.sign(result, "private", true);
        sb = new StringBuffer();
        for (int i = 0; i < keys.length; i++) {
            sb.append(keys[i]);
            sb.append("=");
            sb.append(encodeData(values[i]));
            sb.append("&");
        }
        sb.append("sign");
        sb.append("=");
        sb.append(encodeData(sign));
        return sb.toString();
    }

    private String encodeData(String value) {
        try {
            return URLEncoder.encode(value, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
    }

    class Info {
        /**
         * timeout_express : 30m
         * product_code : QUICK_MSECURITY_PAY
         * total_amount : 0.01
         * subject : 1
         * body : 我是测试数据
         * out_trade_no : IQJZSRC1YMQB5HU
         */
        private String timeout_express = "60m";
        private String product_code = "QUICK_MSECURITY_PAY";
        private String total_amount = "1.00";
        private String subject = "AndroidWH客户端支付";
        private String body = "Android手机一台";
        private String out_trade_no = "wh15515806568";
    }
上一篇下一篇

猜你喜欢

热点阅读