Comments (3)
pay_param就是需要服务器生成。旧版本有详细需要哪些参数。客户端不负责生成
from payandroid.
这我就搞不懂了。我们项目现在支付都是客户端写的,只是参数是服务器传过来的:
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.
是的。支付宝微信Demo里是客户端处理,因为给用户一个参考。但是它们在文档里都标注了secret要放在服务端然后加密生成sign。放在客户端是不安全的。
from payandroid.
Related Issues (17)
- 实时
- 返回NULL? 支付失败 HOT 21
- 微信支付调用后弹出支付失败 HOT 16
- 银联支付也搞进去啊 大兄弟
- [bug]未安装支付宝客户端,支付宝H5pay未打开
- 我自己导入了 支付宝sdk 在引用这个会冲突嘛
- 这个还在维护么 HOT 1
- 能把支付宝微信的库升级一下么? 支付宝发邮件警告了
- 有个困惑? HOT 9
- 11月发布的新版支付宝SDK中:“支付服务生成的支付参数”,是由服务端生成吗? HOT 7
- 微信连支付页面都唤不起来 HOT 1
- 注册Acitivty的时候有误,作者应该更新下! HOT 1
- 请问是在回调方法里将支付结果发送给后台吗?
- 请问appkey,privatekey如何配置 HOT 4
- 您好请问调起支付 这个方法需要的String 类型参数 是怎样得到的 , 我现在拿到 包括appid 在内的七个参数 HOT 1
- 请问微信支付的应用签名是要正式签名的apk吗? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from payandroid.