Blame view

parking-module-pay/src/main/java/com/zteits/pay/util/AliPay.java 3.85 KB
55f68655   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  package com.zteits.pay.util;
  
  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.Locale;
  import java.util.Random;
  
  
  public class AliPay {
     String mPayway, mSubject, mBody, mPrice, mOrderId, mReserve, mCouponId;
     
     private static final int SDK_PAY_FLAG = 1;
  
     private static final int SDK_CHECK_FLAG = 2;
     public void pay(){
        // 订单
        String orderInfo = getOrderInfo(mOrderId, mSubject, mBody, mPrice, mReserve, mCouponId);
        // 对订单做RSA 签名
        String sign = sign(orderInfo);
        System.out.println("orderInfo:" + orderInfo);
        System.out.println("sign:" + sign);
        try {
           // 仅需对sign 做URL编码
           sign = URLEncoder.encode(sign, "UTF-8");
        } catch (UnsupportedEncodingException e) {
           e.printStackTrace();
        }
        // 完整的符合支付宝参数规范的订单信息
        final String payInfo = orderInfo + "&sign=\"" + sign + "\"&" + getSignType();
        
     }
     
     /**
      * sign the order info. 对订单信息进行签名
      * 
      * @param content
      *            待签名订单信息
      */
     public String sign(String content) {
        return SignUtils.sign(content, null);
     }
     
     /**
      * get the sign type we use. 获取签名方式
      * 
      */
     public String getSignType() {
        return "sign_type=\"RSA\"";
     }
     
     /**
      * create the order info. 创建订单信息
      * 
      */
     public String getOrderInfo(String orderId, String subject, String body, String price, String reserve, String couponId) {
  
        // 签约合作者身份ID
        String orderInfo = "partner=" + "\"" + null + "\"";
  
        // 签约卖家支付宝账号
        orderInfo += "&seller_id=" + "\"" + null + "\"";
  
        // 商户网站唯一订单号
        orderInfo += "&out_trade_no=" + "\"" + getOutTradeNo() + "\"";
  
        // 商品名称
        orderInfo += "&subject=" + "\"" + subject + "\"";
  
  
        // 商品详情
        orderInfo += "&body=" + "\"" + "eee" + "\"";//orderId + "####" + Config.getSessionValue(mContext) + "####" + reserve + "####" + couponId + "####" + Config.SERVER_URL +"\"";
  
        // 商品金额
        orderInfo += "&total_fee=" + "\"" + price + "\"";
  
        //服务器异步通知页面路径
        orderInfo += "&notify_url=" + "\"" + "http://120.26.116.79/zteitsrnt/alipay"//"http://alipay.api.rnting.com/notify_url.aspx"
              + "\"";
  
        // 服务接口名称, 固定值
        orderInfo += "&service=\"mobile.securitypay.pay\"";
  
        // 支付类型, 固定值
        orderInfo += "&payment_type=\"1\"";
  
        // 参数编码, 固定值
        orderInfo += "&_input_charset=\"utf-8\"";
  
        // 设置未付款交易的超时时间
        // 默认30分钟,一旦超时,该笔交易就会自动被关闭。
        // 取值范围:1m~15d。
        // m-分钟,h-小时,d-天,1c-当天(无论交易何时创建,都在0点关闭)。
        // 该参数数值不接受小数点,如1.5h,可转换为90m。
        orderInfo += "&it_b_pay=\"30m\"";
  
        // extern_token为经过快登授权获取到的alipay_open_id,带上此参数用户将使用授权的账户进行支付
        // orderInfo += "&extern_token=" + "\"" + extern_token + "\"";
  
        // 支付宝处理完请求后,当前页面跳转到商户指定页面的路径,可空
        orderInfo += "&return_url=\"m.alipay.com\"";
  
        // 调用银行卡支付,需配置此参数,参与签名, 固定值 (需要签约《无线银行卡快捷支付》才能使用)
        // orderInfo += "&paymethod=\"expressGateway\"";
  
        return orderInfo;
     }
     
     public String getOutTradeNo()
       {
         String str = new SimpleDateFormat("MMddHHmmss", Locale.getDefault()).format(new Date());
         Random localRandom = new Random();
         return (str + localRandom.nextInt()).substring(0, 15);
       }
     
  }