-
Notifications
You must be signed in to change notification settings - Fork 7
/
alipay_config.go
153 lines (143 loc) · 4.14 KB
/
alipay_config.go
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package alipay
import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"log"
)
type AlipayConfig struct {
//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
//合作身份者id,以2088开头的16位纯数字
Partner string
//安全检验码,以数字和字母组成的32位字符
Key string
//商户的私钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
Private_key_path []byte
//支付宝公钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
Ali_public_key_path []byte
//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
//签名方式 不需修改
Sign_type string
//字符编码格式 目前支持 gbk 或 utf-8
Input_charset string
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
Cacert string
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
Transport string
//商户私钥
Private_key *rsa.PrivateKey
//支付宝公钥 (验签)
Public_key *rsa.PublicKey
//服务类型(移动支付)
Service string
//卖家支付宝账号
Seller_id string
//异步通知URL
Notify_url string
//
Return_url string
//支付类型 1
Payment_type string
//显示订单消息页面
Show_order_url string
//操作中断返回地址
Wap_merchant_url string
//页面跳转同步通知页面路径
Wap_callback_url string
//Wap_Service
Wap_Service string
}
var AWebConfig = &AlipayConfig{
Partner: "xxxxxxxxxxx",
Key: "xxxxxxxxxxx",
Sign_type: "MD5",
Input_charset: "utf-8",
Cacert: "Cacert",
Transport: "http",
Service: "create_direct_pay_by_user",
Seller_id: "[email protected]",
Notify_url: "/api/pub/alipayWeb/notify",
Return_url: "/api/pub/alipayWeb/return",
Payment_type: "1",
Show_order_url: "/paymentStatus.html",
}
var AMobileConfig = &AlipayConfig{
Partner: "xxxxxxxxxxx",
Key: "xxxxxxxxxxx",
Sign_type: "RSA",
Private_key_path: []byte(`
-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxx
-----END RSA PRIVATE KEY-----
`),
Ali_public_key_path: []byte(`
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxx
-----END PUBLIC KEY-----
`),
Input_charset: "UTF-8",
Cacert: "Cacert",
Transport: "http",
Service: "mobile.securitypay.pay",
Seller_id: "[email protected]",
Notify_url: "/alipayMobile/notify",
Payment_type: "1",
}
var AWapConfig = &AlipayConfig{
Partner: "xxxxxxxxxxx",
Key: "xxxxxxxxxxx",
Sign_type: "MD5",
Private_key_path: []byte(`
-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxx
-----END RSA PRIVATE KEY-----
`),
Ali_public_key_path: []byte(`
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxx
-----END PUBLIC KEY-----
`),
Input_charset: "utf-8",
// Cacert: "Cacert",
Transport: "http",
Service: "alipay.wap.auth.authAndExecute",
Wap_Service: "alipay.wap.trade.create.direct",
Seller_id: "[email protected]",
Notify_url: "/api/pub/alipayWap/notify",
// Payment_type: "1",
Wap_merchant_url: "/api/pub/alipayWap/merchant",
//页面跳转同步通知页面路径
Wap_callback_url: "/api/pub/alipayWap/callback",
Show_order_url: "/paymentStatus.html",
}
func InitKeys(alipayConfig *AlipayConfig) error {
log.Println("init rsakeys begin")
block, _ := pem.Decode(alipayConfig.Private_key_path)
if block == nil {
log.Println("rsaSign private_key error")
return fmt.Errorf("rsaSign pem.Decode error")
}
var err error
alipayConfig.Private_key, err = x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
log.Println("rsaSign ParsePKIXPublicKey error : %v\n", err)
return err
}
block, _ = pem.Decode(alipayConfig.Ali_public_key_path)
if block == nil {
log.Println("public key error")
return err
}
pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
log.Println("rsaSign ParsePKIXPublicKey error : %v\n", err)
return err
}
alipayConfig.Public_key = pubInterface.(*rsa.PublicKey)
log.Println("init rsakeys success ")
return err
}