GithubHelp home page GithubHelp logo

Comments (3)

tsy12321 avatar tsy12321 commented on July 22, 2024

pay_param就是需要服务器生成。旧版本有详细需要哪些参数。客户端不负责生成

from payandroid.

DanteAndroid avatar DanteAndroid commented on July 22, 2024

这我就搞不懂了。我们项目现在支付都是客户端写的,只是参数是服务器传过来的:

    private String buildOrder(PayInfo mPayInfo) {
        StringBuilder orderInfo = new StringBuilder();
        //从unity传过来的json数据中获得的值
        orderInfo.append(strConcatenate("subject", mPayInfo.getProductName())).append("&");
        orderInfo.append(strConcatenate("body", mPayInfo.getDescription())).append("&");
        orderInfo.append(strConcatenate("total_fee", mPayInfo.getPrice())).append("&");
        orderInfo.append(strConcatenate("out_trade_no", mPayInfo.getOrderId())).append("&");
        //固定值
        orderInfo.append(strConcatenate("partner", PartnerConfig.PARTNER)).append("&");
        orderInfo.append(strConcatenate("seller_id", PartnerConfig.SELLER)).append("&");
        orderInfo.append(strConcatenate("payment_type", "1")).append("&");

//		try {//TODO 为什么通知URL需要编码?
//			url = URLEncoder.encode(mPayInfo.getNotifyUrl(),"UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
        orderInfo.append(strConcatenate("notify_url", mPayInfo.getNotifyUrl())).append("&");
        // 固定值:接口名称\字符编码
        orderInfo.append(strConcatenate("service", "mobile.securitypay.pay")).append("&");
        orderInfo.append(strConcatenate("_input_charset", "utf-8")).append("&");
        orderInfo.append(strConcatenate("it_b_pay", "30m"));//此处结尾不能加"&",否则签名会失败
        String sign = "";
        try {
            //对orderInfo签名并编码
            sign = URLEncoder.encode(getRSAsign(orderInfo.toString()), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        orderInfo.append(strConcatenate("&sign", sign)).append("&");
        orderInfo.append(strConcatenate("sign_type", "RSA"));
        return orderInfo.toString();
    }
...

//支付宝支付主方法
    PayTask aliPay = new PayTask((Activity) mContext);
   String result = aliPay.pay(这里传入上面的buildOrder方法拼接的订单字符串);


这种写法是按照支付宝demo来的,而且微信支付也是客户端处理的:

        try{
            if (api == null) {
                api = WXAPIFactory.createWXAPI(ExternalCall.context, Constants.WECHAT_APP_ID, false);
                api.registerApp(Constants.WECHAT_APP_ID);
            }
            PayReq req = new PayReq(); 
            req.appId			= json.getString("appid");
            req.partnerId		= json.getString("partnerid");
            req.prepayId		= json.getString("prepayid");
            req.nonceStr		= json.getString("noncestr");
            req.timeStamp		= json.getString("timestamp");
            req.packageValue	= json.getString("package");
            req.sign			= json.getString("sign");
//        req.extData			= "app data"; // optional
//        Toast.makeText(PayActivity.this, "正常调起支付", Toast.LENGTH_SHORT).show();
            // 在支付之前,如果应用没有注册到微信,应该先调用IWXMsg.registerApp将应用注册到微信
            Log.i(TAG, "StartPay" + json.toString());
            api.sendReq(req);
        }catch(Exception e){
            Log.e("PAY_GET", "异常:"+e.getMessage());
        }

按照您的意思,实际上这些参数都应该服务器处理?

from payandroid.

tsy12321 avatar tsy12321 commented on July 22, 2024

是的。支付宝微信Demo里是客户端处理,因为给用户一个参考。但是它们在文档里都标注了secret要放在服务端然后加密生成sign。放在客户端是不安全的。

from payandroid.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.