java ping++支付

  1. /** 
  2.  *  ━━━━━━神兽出没━━━━━━  
  3.  *   ┏┓   ┏┓  
  4.  *  ┏┛┻━━━┛┻┓  
  5.  *   ┃       ┃ 
  6.  *   ┃   ━   ┃  
  7.  *   ┃ ┳┛ ┗┳  ┃  
  8.  *  ┃       ┃  
  9.  *  ┃   ┻   ┃  
  10.  *  ┃       ┃  
  11.  *  ┗━┓   ┏━┛Code is far away from bug with the animal protecting  
  12.  *    ┃   ┃    神兽保佑,代码无bug  
  13.  *    ┃   ┃  
  14.  *    ┃   ┗━━━┓  
  15.  *    ┃       ┣┓  
  16.  *    ┃       ┏┛  
  17.  *    ┗┓┓┏━┳┓┏┛  
  18.  *     ┃┫┫ ┃┫┫  
  19.  *     ┗┻┛ ┗┻┛  
  20.  *  
  21.  * ━━━━━━感觉萌萌哒━━━━━━  
  22.  */  
  23. package com.gt.gl.controller.pingpp;  
  24.   
  25. import java.util.Calendar;  
  26. import java.util.HashMap;  
  27. import java.util.Map;  
  28.   
  29. import com.pingplusplus.exception.PingppException;  
  30. import com.pingplusplus.model.Charge;  
  31.   
  32. /** 
  33.  * @author why 
  34.  * 
  35.  */  
  36. /** 
  37.  *  alipay:支付宝手机支付 
  38.  *  alipay_wap:支付宝手机网页支付 
  39.  *  alipay_qr:支付宝扫码支付 
  40.  *  alipay_pc_direct:支付宝 PC 网页支付 
  41.  *  bfb:百度钱包移动快捷支付 
  42.  *  bfb_wap:百度钱包手机网页支付 
  43.  *  upacp:银联全渠道支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系) 
  44.  *  upacp_wap:银联全渠道手机网页支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系) 
  45.  *  upacp_pc:银联 PC 网页支付 
  46.  *  cp_b2b:银联企业网银支付 
  47.  *  wx:微信支付 
  48.  *  wx_pub:微信公众号支付 
  49.  *  wx_pub_qr:微信公众号扫码支付 
  50.  *  wx_wap:微信WAP支付 
  51.  *  yeepay_wap:易宝手机网页支付 
  52.  *  jdpay_wap:京东手机网页支付 
  53.  *  cnp_u:应用内快捷支付(银联) 
  54.  *  cnp_f:应用内快捷支付(外卡) 
  55.  *  applepay_upacp:Apple Pay 
  56.  *  fqlpay_wap:分期乐支付 
  57.  *  qgbc_wap:量化派支付 
  58.  *  cmb_wallet:招行一网通 
  59.  */  
  60. public class PingPlusCharge {  
  61.     private String appId;    
  62.         
  63.         
  64.     PingPlusCharge(String appId) {    
  65.         this.appId = appId;    
  66.     }    
  67.     /** 
  68.      * 支付方法 
  69.      * @param orderNo 
  70.      * @param amount 
  71.      * @param subject 
  72.      * @param body 
  73.      * @param channel 
  74.      * @param clientIP 
  75.      * @return 
  76.      */  
  77.     public String createCharge(String orderNo, int amount, String subject, String body, String channel, String clientIP) {    
  78.         Map<String, Object> chargeMap = new HashMap<String, Object>();    
  79.         chargeMap.put("amount", amount);//金额    
  80.         chargeMap.put("currency""cny");    
  81.         chargeMap.put("subject", subject);    
  82.         chargeMap.put("body", body);    
  83.         chargeMap.put("order_no", orderNo); //订单号   
  84.         chargeMap.put("channel", channel);  //支付渠道  
  85.         Calendar cal = Calendar.getInstance();    
  86.         cal.add(Calendar.MINUTE, 15);//15分钟失效    
  87.         long timestamp = cal.getTimeInMillis()/ 1000L;    
  88.         chargeMap.put("time_expire", timestamp); //订单失效时间,用 Unix 时间戳表示。时间范围在订单创建后的 1 分钟到 15 天,默认为 1 天,创建时间以 Ping++ 服务器时间为准。 微信对该参数的有效值限制为 2 小时内;银联对该参数的有效值限制为 1 小时内。   
  89.         chargeMap.put("client_ip", clientIP); // 客户端 ip 地址(ipv4)    
  90.         Map<String, String> app = new HashMap<String, String>();    
  91.         app.put("id", appId);//支付使用的 app 对象的 id   
  92.         chargeMap.put("app", app);    
  93.         String chargeString = null;    
  94.         try {    
  95.             //发起交易请求    
  96.             Charge charge = Charge.create(chargeMap);    
  97.             // 传到客户端请先转成字符串 .toString(), 调该方法,会自动转成正确的 JSON 字符串    
  98.             chargeString = charge.toString();  
  99.         } catch (PingppException e) {    
  100.             e.printStackTrace();    
  101.         }    
  102.         return chargeString;    
  103.     }    
  104. }  
发起支付:

[java]  view plain  copy
  1. /** 
  2.  *  ━━━━━━神兽出没━━━━━━  
  3.  *   ┏┓   ┏┓  
  4.  *  ┏┛┻━━━┛┻┓  
  5.  *   ┃       ┃ 
  6.  *   ┃   ━   ┃  
  7.  *   ┃ ┳┛ ┗┳  ┃  
  8.  *  ┃       ┃  
  9.  *  ┃   ┻   ┃  
  10.  *  ┃       ┃  
  11.  *  ┗━┓   ┏━┛Code is far away from bug with the animal protecting  
  12.  *    ┃   ┃    神兽保佑,代码无bug  
  13.  *    ┃   ┃  
  14.  *    ┃   ┗━━━┓  
  15.  *    ┃       ┣┓  
  16.  *    ┃       ┏┛  
  17.  *    ┗┓┓┏━┳┓┏┛  
  18.  *     ┃┫┫ ┃┫┫  
  19.  *     ┗┻┛ ┗┻┛  
  20.  *  
  21.  * ━━━━━━感觉萌萌哒━━━━━━  
  22.  */  
  23. package com.gt.gl.controller.pingpp;  
  24.   
  25. import java.io.File;  
  26.   
  27. import javax.servlet.http.HttpServletRequest;  
  28.   
  29. import net.sf.json.JSONObject;  
  30.   
  31. import org.springframework.beans.factory.annotation.Autowired;  
  32. import org.springframework.stereotype.Controller;  
  33. import org.springframework.web.bind.annotation.RequestBody;  
  34. import org.springframework.web.bind.annotation.RequestMapping;  
  35. import org.springframework.web.bind.annotation.RequestMethod;  
  36. import org.springframework.web.bind.annotation.ResponseBody;  
  37.   
  38. import com.gt.gl.controller.base.BaseController;  
  39. import com.gt.gl.entity.base.MsMessage;  
  40. import com.pingplusplus.Pingpp;  
  41.   
  42. /** 
  43.  * @author why 
  44.  * 
  45.  */  
  46.   
  47. @Controller  
  48. @RequestMapping("/pingpppay")  
  49. public class PingPlusPayController extends BaseController {  
  50.     @Autowired  
  51.     private MsMessage msMessage;  
  52.     /**  
  53.      * Pingpp 管理平台对应的 API Key  
  54.      */    
  55.     private final static String apiKey = "";  
  56.     
  57.     
  58.     /**  
  59.      * Pingpp 管理平台对应的应用 ID  
  60.      */    
  61.     private final static String appId = "";    
  62.     /**  
  63.      * 你生成的私钥路径  
  64.      */    
  65.     private final static String privateKeyFilePath = 你的私钥路径rsa_private_key.pem";  
  66.     /** 
  67.      *  alipay:支付宝手机支付 
  68.      *  alipay_wap:支付宝手机网页支付 
  69.      *  alipay_qr:支付宝扫码支付 
  70.      *  alipay_pc_direct:支付宝 PC 网页支付 
  71.      *  bfb:百度钱包移动快捷支付 
  72.      *  bfb_wap:百度钱包手机网页支付 
  73.      *  upacp:银联全渠道支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系) 
  74.      *  upacp_wap:银联全渠道手机网页支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系) 
  75.      *  upacp_pc:银联 PC 网页支付 
  76.      *  cp_b2b:银联企业网银支付 
  77.      *  wx:微信支付 
  78.      *  wx_pub:微信公众号支付 
  79.      *  wx_pub_qr:微信公众号扫码支付 
  80.      *  wx_wap:微信WAP支付 
  81.      *  yeepay_wap:易宝手机网页支付 
  82.      *  jdpay_wap:京东手机网页支付 
  83.      *  cnp_u:应用内快捷支付(银联) 
  84.      *  cnp_f:应用内快捷支付(外卡) 
  85.      *  applepay_upacp:Apple Pay 
  86.      *  fqlpay_wap:分期乐支付 
  87.      *  qgbc_wap:量化派支付 
  88.      *  cmb_wallet:招行一网通 
  89.      */  
  90.     /** 
  91.      *  
  92.      * @param orderNo 订单号商户订单号,适配每个渠道对此参数的要求,必须在商户系统内唯一。(alipay: 1-64 位, wx: 2-32 位,bfb: 1-20 位,upacp: 8-40 位,yeepay_wap:1-50 位,jdpay_wap:1-30 位,cnp_u:8-20 位,cnp_f:8-20 位,cmb_wallet:6 位或 10 位纯数字字符串。注:除cmb_wallet外的其他渠道推荐使用 8-20 位,要求数字或字母,不允许特殊字符)。 
  93.      * @param amount 订单总金额, 单位为对应币种的最小货币单位,例如:人民币为分(如订单总金额为 1 元,此处请填 100)。 
  94.      * @param subject 商品的标题,该参数最长为 32 个 Unicode 字符,银联全渠道(upacp/upacp_wap)限制在 32 个字节 
  95.      * @param body 商品的描述信息,该参数最长为 128 个 Unicode 字符,yeepay_wap 对于该参数长度限制为 100 个 Unicode 字符。 
  96.      * @param channel 支付渠道 
  97.      * @param clientIP 发起支付请求客户端的 IP 地址,格式为 IPV4,如: 127.0.0.1 
  98.      * @return 
  99.      */  
  100.     @RequestMapping(value = "charge", method = RequestMethod.POST)  
  101.     @ResponseBody  
  102.     public String charge(String orderNo,String amount,String channel,HttpServletRequest request) throws Exception{    
  103.           
  104.         // 设置 API Key    
  105.         Pingpp.apiKey = apiKey;    
  106.     
  107.         // 设置私钥路径,用于请求签名    
  108.         Pingpp.privateKeyPath = privateKeyFilePath;    
  109.         PingPlusCharge charge=new PingPlusCharge(appId);    
  110.         String clientIP = getClientIpAddress(request);  
  111.         String subject = "";  
  112.         String body = "";  
  113.         String chargeString=charge.createCharge(orderNo,Integer.parseInt("1"),subject,body,channel,clientIP);    
  114.         System.out.println("======chargeString=======:"+chargeString);  
  115.         this.setMsMessage(msMessage, 0null, chargeString);  
  116.         System.out.println("ping++支付接口:"+JSONObject.fromObject(msMessage).toString());  
  117.         return JSONObject.fromObject(msMessage).toString();    
  118.     }  
  119.     public static void main(String[] args) {  
  120. //      System.out.println(System.getProperty("user.dir"));  
  121.         PingPlusPayController p = new PingPlusPayController();  
  122.         System.out.println(p.getClass().getClassLoader().getResource("").getPath());  
  123.     }  
  124.       
  125. }  
把ping++ 平台返回的字符串直接传给客户端,即可调起支付。

猜你喜欢

转载自blog.csdn.net/qq_31546841/article/details/80271329
今日推荐