- /**
- * ━━━━━━神兽出没━━━━━━
- * ┏┓ ┏┓
- * ┏┛┻━━━┛┻┓
- * ┃ ┃
- * ┃ ━ ┃
- * ┃ ┳┛ ┗┳ ┃
- * ┃ ┃
- * ┃ ┻ ┃
- * ┃ ┃
- * ┗━┓ ┏━┛Code is far away from bug with the animal protecting
- * ┃ ┃ 神兽保佑,代码无bug
- * ┃ ┃
- * ┃ ┗━━━┓
- * ┃ ┣┓
- * ┃ ┏┛
- * ┗┓┓┏━┳┓┏┛
- * ┃┫┫ ┃┫┫
- * ┗┻┛ ┗┻┛
- *
- * ━━━━━━感觉萌萌哒━━━━━━
- */
- 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;
- /**
- * @author why
- *
- */
- /**
- * alipay:支付宝手机支付
- * alipay_wap:支付宝手机网页支付
- * alipay_qr:支付宝扫码支付
- * alipay_pc_direct:支付宝 PC 网页支付
- * bfb:百度钱包移动快捷支付
- * bfb_wap:百度钱包手机网页支付
- * upacp:银联全渠道支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系)
- * upacp_wap:银联全渠道手机网页支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系)
- * upacp_pc:银联 PC 网页支付
- * cp_b2b:银联企业网银支付
- * wx:微信支付
- * wx_pub:微信公众号支付
- * wx_pub_qr:微信公众号扫码支付
- * wx_wap:微信WAP支付
- * yeepay_wap:易宝手机网页支付
- * jdpay_wap:京东手机网页支付
- * cnp_u:应用内快捷支付(银联)
- * cnp_f:应用内快捷支付(外卡)
- * applepay_upacp:Apple Pay
- * fqlpay_wap:分期乐支付
- * qgbc_wap:量化派支付
- * cmb_wallet:招行一网通
- */
- public class PingPlusCharge {
- private String appId;
- PingPlusCharge(String appId) {
- this.appId = appId;
- }
- /**
- * 支付方法
- * @param orderNo
- * @param amount
- * @param subject
- * @param body
- * @param channel
- * @param clientIP
- * @return
- */
- 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);//15分钟失效
- long timestamp = cal.getTimeInMillis()/ 1000L;
- chargeMap.put("time_expire", timestamp); //订单失效时间,用 Unix 时间戳表示。时间范围在订单创建后的 1 分钟到 15 天,默认为 1 天,创建时间以 Ping++ 服务器时间为准。 微信对该参数的有效值限制为 2 小时内;银联对该参数的有效值限制为 1 小时内。
- chargeMap.put("client_ip", clientIP); // 客户端 ip 地址(ipv4)
- Map<String, String> app = new HashMap<String, String>();
- app.put("id", appId);//支付使用的 app 对象的 id
- chargeMap.put("app", app);
- String chargeString = null;
- try {
- //发起交易请求
- Charge charge = Charge.create(chargeMap);
- // 传到客户端请先转成字符串 .toString(), 调该方法,会自动转成正确的 JSON 字符串
- chargeString = charge.toString();
- } catch (PingppException e) {
- e.printStackTrace();
- }
- return chargeString;
- }
- }
- /**
- * ━━━━━━神兽出没━━━━━━
- * ┏┓ ┏┓
- * ┏┛┻━━━┛┻┓
- * ┃ ┃
- * ┃ ━ ┃
- * ┃ ┳┛ ┗┳ ┃
- * ┃ ┃
- * ┃ ┻ ┃
- * ┃ ┃
- * ┗━┓ ┏━┛Code is far away from bug with the animal protecting
- * ┃ ┃ 神兽保佑,代码无bug
- * ┃ ┃
- * ┃ ┗━━━┓
- * ┃ ┣┓
- * ┃ ┏┛
- * ┗┓┓┏━┳┓┏┛
- * ┃┫┫ ┃┫┫
- * ┗┻┛ ┗┻┛
- *
- * ━━━━━━感觉萌萌哒━━━━━━
- */
- 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;
- /**
- * @author why
- *
- */
- @Controller
- @RequestMapping("/pingpppay")
- public class PingPlusPayController extends BaseController {
- @Autowired
- private MsMessage msMessage;
- /**
- * Pingpp 管理平台对应的 API Key
- */
- private final static String apiKey = "";
- /**
- * Pingpp 管理平台对应的应用 ID
- */
- private final static String appId = "";
- /**
- * 你生成的私钥路径
- */
- private final static String privateKeyFilePath = 你的私钥路径rsa_private_key.pem";
- /**
- * alipay:支付宝手机支付
- * alipay_wap:支付宝手机网页支付
- * alipay_qr:支付宝扫码支付
- * alipay_pc_direct:支付宝 PC 网页支付
- * bfb:百度钱包移动快捷支付
- * bfb_wap:百度钱包手机网页支付
- * upacp:银联全渠道支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系)
- * upacp_wap:银联全渠道手机网页支付(2015 年 1 月 1 日后的银联新商户使用。若有疑问,请与 Ping++ 或者相关的收单行联系)
- * upacp_pc:银联 PC 网页支付
- * cp_b2b:银联企业网银支付
- * wx:微信支付
- * wx_pub:微信公众号支付
- * wx_pub_qr:微信公众号扫码支付
- * wx_wap:微信WAP支付
- * yeepay_wap:易宝手机网页支付
- * jdpay_wap:京东手机网页支付
- * cnp_u:应用内快捷支付(银联)
- * cnp_f:应用内快捷支付(外卡)
- * applepay_upacp:Apple Pay
- * fqlpay_wap:分期乐支付
- * qgbc_wap:量化派支付
- * cmb_wallet:招行一网通
- */
- /**
- *
- * @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 位,要求数字或字母,不允许特殊字符)。
- * @param amount 订单总金额, 单位为对应币种的最小货币单位,例如:人民币为分(如订单总金额为 1 元,此处请填 100)。
- * @param subject 商品的标题,该参数最长为 32 个 Unicode 字符,银联全渠道(upacp/upacp_wap)限制在 32 个字节
- * @param body 商品的描述信息,该参数最长为 128 个 Unicode 字符,yeepay_wap 对于该参数长度限制为 100 个 Unicode 字符。
- * @param channel 支付渠道
- * @param clientIP 发起支付请求客户端的 IP 地址,格式为 IPV4,如: 127.0.0.1
- * @return
- */
- @RequestMapping(value = "charge", method = RequestMethod.POST)
- @ResponseBody
- public String charge(String orderNo,String amount,String channel,HttpServletRequest request) throws Exception{
- // 设置 API Key
- 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) {
- // System.out.println(System.getProperty("user.dir"));
- PingPlusPayController p = new PingPlusPayController();
- System.out.println(p.getClass().getClassLoader().getResource("").getPath());
- }
- }