感谢2015年4月20的 Ping++技术支持
耐心指导~
流程:
- 客户端 对 服务端发出支付请求
- 服务端 根据请求,设置相应的extra. //这个extra不是额外的呀,是必须的!
- 客户端 接收 服务端返回的Charge对象
我把ping++的处理 放在service层中了~~
// 测试ping++交易 // 返回Charge对象 public Charge transaction() { Charge charge = null; Pingpp.apiKey = "sk_test_q540q9GanD0O4eLWDSqDa5SC"; Map<String, Object> chargeMap = new HashMap<String, Object>(); // 某些渠道需要添加extra参数,具体参数详见接口文档 chargeMap.put("amount", 100); chargeMap.put("currency", "cny"); chargeMap.put("subject", "Your Subject"); chargeMap.put("body", "Your Body"); chargeMap.put("order_no", "1111"); chargeMap.put("channel", "alipay_wap"); chargeMap.put("client_ip", "127.0.0.1"); Map<String, String> app = new HashMap<String, String>(); app.put("id", "app_GeTunDi9WzzTyfDG"); Map<String, String> extramap = new HashMap<String, String>(); //extra的参数根据文档: https://pingxx.com/document/api#api-c-new extramap.put("success_url", "http://127.0.0.1:8080/PartTimeJob/pinus_webview.html"); chargeMap.put("extra", extramap); chargeMap.put("app", app); try { // 发起交易请求 charge = Charge.create(chargeMap); System.out.println(charge); } catch (PingppException e) { e.printStackTrace(); } return charge; }
HTML5客户端,用的是ping++HTML5 SDK 的example.
function wap_pay(channel) { var amount = document.getElementById('amount').value * 100; var pay_url = "deposit-transaction"; // 改成自己的url,就行了~其他的不用改. var xhr = new XMLHttpRequest(); xhr.open("POST", pay_url, true); xhr.setRequestHeader("Content-type", "application/json"); xhr.send(JSON.stringify({ channel: channel, amount: amount })); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); pingpp.createPayment(xhr.responseText, function(result, err) { console.log(result); console.log(err); }); } } }
欢迎提建议~
时间: 2024-10-18 13:44:37