java ping++支付
其他
2018-07-31 18:10:06
阅读次数: 0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- package com.gt.gl.controller.pingpp;
-
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.Map;
-
- import com.pingplusplus.exception.PingppException;
- import com.pingplusplus.model.Charge;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class PingPlusCharge {
- private String appId;
-
-
- PingPlusCharge(String appId) {
- this.appId = appId;
- }
-
-
-
-
-
-
-
-
-
-
- public String createCharge(String orderNo, int amount, String subject, String body, String channel, String clientIP) {
- Map<String, Object> chargeMap = new HashMap<String, Object>();
- chargeMap.put("amount", amount);
- chargeMap.put("currency", "cny");
- chargeMap.put("subject", subject);
- chargeMap.put("body", body);
- chargeMap.put("order_no", orderNo);
- chargeMap.put("channel", channel);
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.MINUTE, 15);
- long timestamp = cal.getTimeInMillis()/ 1000L;
- chargeMap.put("time_expire", timestamp);
- chargeMap.put("client_ip", clientIP);
- Map<String, String> app = new HashMap<String, String>();
- app.put("id", appId);
- chargeMap.put("app", app);
- String chargeString = null;
- try {
-
- Charge charge = Charge.create(chargeMap);
-
- chargeString = charge.toString();
- } catch (PingppException e) {
- e.printStackTrace();
- }
- return chargeString;
- }
- }
发起支付:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- package com.gt.gl.controller.pingpp;
-
- import java.io.File;
-
- import javax.servlet.http.HttpServletRequest;
-
- import net.sf.json.JSONObject;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import com.gt.gl.controller.base.BaseController;
- import com.gt.gl.entity.base.MsMessage;
- import com.pingplusplus.Pingpp;
-
-
-
-
-
-
- @Controller
- @RequestMapping("/pingpppay")
- public class PingPlusPayController extends BaseController {
- @Autowired
- private MsMessage msMessage;
-
-
-
- private final static String apiKey = "";
-
-
-
-
-
- private final static String appId = "";
-
-
-
- private final static String privateKeyFilePath = 你的私钥路径rsa_private_key.pem";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @RequestMapping(value = "charge", method = RequestMethod.POST)
- @ResponseBody
- public String charge(String orderNo,String amount,String channel,HttpServletRequest request) throws Exception{
-
-
- Pingpp.apiKey = apiKey;
-
-
- Pingpp.privateKeyPath = privateKeyFilePath;
- PingPlusCharge charge=new PingPlusCharge(appId);
- String clientIP = getClientIpAddress(request);
- String subject = "";
- String body = "";
- String chargeString=charge.createCharge(orderNo,Integer.parseInt("1"),subject,body,channel,clientIP);
- System.out.println("======chargeString=======:"+chargeString);
- this.setMsMessage(msMessage, 0, null, chargeString);
- System.out.println("ping++支付接口:"+JSONObject.fromObject(msMessage).toString());
- return JSONObject.fromObject(msMessage).toString();
- }
- public static void main(String[] args) {
-
- PingPlusPayController p = new PingPlusPayController();
- System.out.println(p.getClass().getClassLoader().getResource("").getPath());
- }
-
- }
把ping++ 平台返回的字符串直接传给客户端,即可调起支付。
转载自blog.csdn.net/qq_31546841/article/details/80271329