checl_test.go
12.0 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package socialwork_sdk
import (
"encoding/json"
"gitlab.workai.com.cn/chenang/socialwork-sdk/model"
"testing"
)
const (
KEY = "fbb416bfd0a242419e6528f2"
IV = "0f6ce46636264d66"
//客户私钥
PRIVATEKEY = `-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL+HIjm9wYlMx5dR
hCGw9Uw5X1ZKPUfOvKXq/8mIuNVtH2ls6jz1fBlhoSHrYMjxY5t7EPSRZzOLeqGI
7FKbwlHPLAC4cN3njho8TE4Ao7EqipG7L81qHL6Wll/NrziP67+dDROG0ozscmNh
kq0JFxIkxQn3aKGbeEdJbLcLRRM7AgMBAAECgYEAn72Rah89v8nt3eL7FS6GKGDh
hxK8MZvX83oghHIn1roArOlOJDGKo5Ct16B9RJsvvInUBmcPcAow6XFNyUhntGnk
evnBZSPz8SJlwGMTTz/P4ebQURrcup5UejQzmBOSXrIXsrW4Ty0AdvnwM1OB/lmz
tQZyU3xMzK6QbXJkCgECQQDqWeR9/gBwWZLkZBPQASxWbb7NKwyCNN7clzMZv6MN
ea8sR7Zp6cNfPtfcVVTeHRX/sXRhB7inRyLi/ec3dSJBAkEA0TiGYiTv1l5prTCC
PK6lyShDK9SR8ZBcSxO5KsttFeOs3f9l2uU0ddd8fAuLJPm2xjd3RAbnH9dAfEC1
GXoeewJBAJ/aB0iFnIkGIHNXbEhCtJqTq0VJavPZ2nZ/UCTtGexUJ0+97shZ4qEy
PY2WSxhioKHTyn1xBdxcYoiRBklGxcECQAqDOZVi3744vjyajGC6MdBauo1QQAkQ
ROLs2cgBsrh/2SbKd3a5P5qQOkwNVG+GMJ3jGZYMdr6N1UqpAbCHB1MCQH1aSvf2
+CXW9fbkUz+qyjIWLN0pDyI+uh+zAHRRs9sL5UVOLfyU03W3120bUL7aekrbynP8
1+ihe8QolWZgvUk=
-----END PRIVATE KEY-----`
//平台公钥
PUBLICKEY = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHk0VRd3+CqwUHA2jC4dzrqe7/
pjX8BTbC7T7DnzAGO7iN09kf2abbzudLTM+xbOKr2wSTLkhffBhycZ4zlf3PuVu/
KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm
3YZBKCNST3LB1JNSeQIDAQAB
-----END PUBLIC KEY-----`
IP = "http://47.110.250.177:20000/"
//IP = "http://127.0.0.1:51393/"
STR = `{"response_type":"code","client_id":"432437055486697481","redirect_uri":"https://dev3.workai.com.cn/wso-workai?state=socialwork_strait_certification_list","state":"client_credential","scope":"global_access:end_user","user_mobile":"13301169757","user_name":"sasl_dispose","callback":"","certification":"0","ptcode":"730088256896503808","path_type":"","path":""}`
V1DATA = "Wxy8h961GO12QmdOdwOYaUZdy6P+o67Olid6YbbjP+SiZNKYofmbQ33eyixsWXIP33sLIrrUrYZ/BNd1+iC8Bng9itBpIcJEfO7fJX9+8Sgp+5hORLESdPRoiyIjeQMX1JKpBk0Uiu7eSsxRRepi33oMi1+580LtFa91lc44PAwnrAEPoTZbEpPQQQmNPrGM0DzmZRUxEIT/SajlwoNg34DvKrGpsb2g8GZ7wUR8GuTOYUg2odF8WjTWNj2GWuzCUw8WPN8FGXdgTzRMn0glivn5SizGmJn0oOJZxo4JRG0Q6h0hV3xi8nPtvwjyOdy0Wspjcd4jQny1jaOKCaPg/5CRLWdmQKLE9d7UhSyQoQ6jzNxEkd/r7vAbtuvRfwvB6zN7NKODjVc/kJf7qovou8u6k2xBGQ7C1CT8wULjqRy3bAYfJ4A5YYWIwtMPJ/l1swlEYsalq5M4Y1g5RjnX1auMczdhnTCOzNeXm2tTJSQ="
V1SIGN = "qTxPJ0t4vW6cMIMYw5vQukG+BnsUY0ku5S1h9TM/IHqJVa0VU5Q7FXxgy0I6T6R12jDZ37+R9RxeEBzO5Fc3rfMWQQfcfGfLgRsbhHSjF0In9T72QHKmzn2upArfCArNlDJh+tC3FvTG9BTMfztlLRlXmVJJ7oTqgJDcZ4m5IqU="
)
var client *OrderClient
func init() {
client = NewOrderClient(KEY, IV, PRIVATEKEY, PUBLICKEY, IP)
}
func TestCheckParams(t *testing.T) {
b := `{"response_type":"code","client_id":"432437055486697481","redirect_uri":"https://dev3.workai.com.cn/wso-workai?state=socialwork_strait_certification_list","state":"client_credential","scope":"global_access:end_user","user_mobile":"13301169757","user_name":"sasl_dispose","callback":"http://tjianke.tcl.com/wxapp.php/sdata/identNotice","certification":"0","ptcode":"638103470397722624","path_type":"PathType","path":"Path"}`
if err := checkParams("AUTHORIZE", b); err != nil {
t.Logf("AUTHORIZE err : %+v", err)
}
b = `{"items":{"name":"新的测试订单","customer_name":"","service_contract_no":"新服务合同543534543","bill_month":1638288000,"payer_object_type":"customer","payer_object_name":"","electron_contract_template_name":"","settlement_org_id":"635981601368444928","has_auto_create":"oneself","payer_name":"","payer_mobile":"","provide_mode":"","callback":"http://47.110.250.177:20000/socialwork/v1/external/callbacktext"}}`
if err := checkParams("CREATEORDER", b); err != nil {
t.Logf("CREATEORDER err : %+v", err)
}
b = `{"id":"728622438832672768","items":[{"user_name":"人员姓名","user_mobile":"13301189876","id_card_no":"110101199003077192","bank_name":"招商银行","bank_card":"621083011111111119","total_salary":"1000","comment":"任务成果备注","job_name":"任务名称","begin_time":1642576824,"end_time":1643527224,"job_type":"会务服务","work_place":"工作地址","salary_unit":"order","salary":"100.00","confirm_type":"oneself","open_account_bank":"开户行","open_account_place":"开户地","open_bank_no":"开户行号","industry_code":"","extra":"","bank_payment_id":"","work_load":"","interval_price":"","real_total_salary":""},{"user_name":"人员姓名1","user_mobile":"13301189877","id_card_no":"110101199003074151","bank_name":"招商银行","bank_card":"621083011111111119","total_salary":"2000","comment":"任务成果备注1","job_name":"任务名称1","begin_time":1642576824,"end_time":1643527224,"job_type":"会务服务","work_place":"工作地址1","salary_unit":"order","salary":"200.00","confirm_type":"oneself","open_account_bank":"开户行1","open_account_place":"开户地1","open_bank_no":"开户行号1","industry_code":"","extra":"","bank_payment_id":"","work_load":"","interval_price":"","real_total_salary":""}]}`
if err := checkParams("ADDFREEDOMEEMP", b); err != nil {
t.Logf("ADDFREEDOMEEMP err : %+v", err)
}
b = `{"id":"690313836787404802","file_type":"id_card_front_image","content":"6ZmE5Lu25YaF5a65","trace_no":"dsdsds"}`
if err := checkParams("UPLOADATTACHMENT", b); err != nil {
t.Logf("UPLOADATTACHMENT err : %+v", err)
}
b = `{"id":"695762134566440960","file_type":"id_card_front_image","url":"http://hbimg.b0.upaiyun.com/32f065b3afb3fb36b75a5cbc9034s051b1050e1e6b6e199-Ml6q9F_fw320","trace_no":"dsdsds"}`
if err := checkParams("UPLOADATTACHMENTBYURL", b); err != nil {
t.Logf("UPLOADATTACHMENTBYURL err : %+v", err)
}
b = `{"id":"705537141886685184"}`
if err := checkParams("ORDERINFO", b); err != nil {
t.Logf("ORDERINFO err : %+v", err)
}
b = `{"id":"719706386803462144"}`
if err := checkParams("FREEDOMEMOSTATUS", b); err != nil {
t.Logf("FREEDOMEMOSTATUS err : %+v", err)
}
b = `{"id":"30207117494289"}`
if err := checkParams("SUBACCOUNTBALANCE", b); err != nil {
t.Logf("SUBACCOUNTBALANCE err : %+v", err)
}
b = `{"order_id":"723262661785030656","detail_id":"723262661785030657","user_name":"杨舟","user_mobile":"12203987657","user_id_card":"42108719910802122743","bank_name":"中国建设银行","bank_card":"621733002230003638850","update_fields":["bank_name","bank_card"]}`
if err := checkParams("UPDATEORDERDETAIL", b); err != nil {
t.Logf("UPDATEORDERDETAIL err : %+v", err)
}
b = `{"id":"700814624890556416"}`
if err := checkParams("EXISTRECEIPT", b); err != nil {
t.Logf("EXISTRECEIPT err : %+v", err)
}
b = `{"file_id":[],"type":"pa","order_id":"700814624890556416"}`
if err := checkParams("DOWNLOADRECEIPT", b); err != nil {
t.Logf("DOWNLOADRECEIPT err : %+v", err)
}
b = `{"id":"728622438832672768","bank":"银行民称","recharge_date":1639639779,"serial_no":"76547654765","setting_status":false,"pt_code":""}`
if err := checkParams("PAYORDER", b); err != nil {
t.Logf("PAYORDER err : %+v", err)
}
b = `{"name":"测试的订单20220210","service_contract_no":"676573793673547776","bill_month":1644485537,"payer_object_type":"customer","settlement_org_id":"676432056892264448","payer_name":"","payer_mobile":"","provide_mode":"","details":[{"user_name":"覃超","user_mobile":"18320960031","id_card_no":"430723199002143210","bank_name":"招商银行","bank_card":"6226096804210467","total_salary":"4.94","comment":"","job_name":"佣金提现申请金额","begin_time":0,"end_time":0,"job_type":"","work_place":"","salary_unit":"单","salary":"","confirm_type":"","open_account_bank":"","open_account_place":"","open_bank_no":"","industry_code":"","extra":"","bank_payment_id":"","work_load":"","interval_price":"","real_total_salary":""}],"Callback":"","setting_status":false,"pt_code":""}`
if err := checkParams("PAYORDERV1", b); err != nil {
t.Logf("PAYORDERV1 err : %+v", err)
}
b = `{"filter":{"mobile":"13301169755"}}`
if err := checkParams("USERINFO", b); err != nil {
t.Logf("USERINFO err : %+v", err)
}
b = `{"user_id":"705485356060905472","mobile":"18881652932"}`
if err := checkParams("UPDATEMOBILE", b); err != nil {
t.Logf("UPDATEMOBILE err : %+v", err)
}
b = `{"name":"聂顺成","mobile":"15017402918","id_num":"341322190709230027","id_card_back":"http://hrshare.oss-cn-shenzhen.aliyuncs.com/hrshare/2022/04/06/frontCard151211551394418626561.png","id_card_front":"http://hrshare.oss-cn-shenzhen.aliyuncs.com/hrshare/2022/04/06/backCard121511551394418626561.png","callback":"https://hrshare.tacll.com/prod-api/app/wxApp/spiritedCallback"}`
if err := checkParams("CREATEEMPLOYMENTPOOL", b); err != nil {
t.Logf("CREATEEMPLOYMENTPOOL err : %+v", err)
}
}
func checkParams(businessCode, reqBody string) error {
switch businessCode {
case "AUTHORIZE":
var authorize model.Authorize
if err := json.Unmarshal([]byte(reqBody), &authorize); err != nil {
return err
}
return nil
case "CREATEORDER":
var createOrder model.CreateOrder
if err := json.Unmarshal([]byte(reqBody), &createOrder); err != nil {
return err
}
return nil
case "ADDFREEDOMEEMP":
var freedomEmps model.FreedomEmps
if err := json.Unmarshal([]byte(reqBody), &freedomEmps); err != nil {
return err
}
return nil
case "UPLOADATTACHMENT":
var uploadFreedomEmps model.UploadFreedomEmps
if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmps); err != nil {
return err
}
return nil
case "UPLOADATTACHMENTBYURL":
var uploadFreedomEmpsByUrl model.UploadFreedomEmpsByUrl
if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmpsByUrl); err != nil {
return err
}
return nil
case "ORDERINFO":
var simpleOrderInfo model.SimpleOrderInfo
if err := json.Unmarshal([]byte(reqBody), &simpleOrderInfo); err != nil {
return err
}
return nil
case "FREEDOMEMOSTATUS":
var freedomEmpStatus model.FreedomEmpStatus
if err := json.Unmarshal([]byte(reqBody), &freedomEmpStatus); err != nil {
return err
}
return nil
case "SUBACCOUNTBALANCE":
var subAccountBalance model.SubAccountBalance
if err := json.Unmarshal([]byte(reqBody), &subAccountBalance); err != nil {
return err
}
return nil
case "UPDATEORDERDETAIL":
var updateOrderDetail model.UpdateOrderDetail
if err := json.Unmarshal([]byte(reqBody), &updateOrderDetail); err != nil {
return err
}
return nil
case "EXISTRECEIPT":
var receipt model.Receipt
if err := json.Unmarshal([]byte(reqBody), &receipt); err != nil {
return err
}
return nil
case "DOWNLOADRECEIPT":
var downloadReceipt model.DownloadReceipt
if err := json.Unmarshal([]byte(reqBody), &downloadReceipt); err != nil {
return err
}
return nil
case "PAYORDER":
var payOrder model.PayOrder
if err := json.Unmarshal([]byte(reqBody), &payOrder); err != nil {
return err
}
return nil
case "USERINFO":
var getUserInfo model.GetUserInfo
if err := json.Unmarshal([]byte(reqBody), &getUserInfo); err != nil {
return err
}
return nil
case "PAYORDERV1":
var mergeCreateOrder model.MergeCreateOrder
if err := json.Unmarshal([]byte(reqBody), &mergeCreateOrder); err != nil {
return err
}
return nil
case "UPDATEMOBILE":
var updateMobile model.UpdateMobile
if err := json.Unmarshal([]byte(reqBody), &updateMobile); err != nil {
return err
}
return nil
case "CREATEEMPLOYMENTPOOL":
var createEmploymentPool model.CreateEmploymentPool
if err := json.Unmarshal([]byte(reqBody), &createEmploymentPool); err != nil {
return err
}
return nil
}
return nil
}
func TestEncryption(t *testing.T) {
data, sign, err := client.EncryptAndSign([]byte(STR))
if err != nil {
t.Logf("加密和签名错误 err : %+v", err)
}
if data != V1DATA {
t.Logf("加密数据与期望值不匹配 err : %+v", err)
}
if sign != V1SIGN {
t.Logf("签名数据与期望值不匹配 err : %+v", err)
}
}
/*func TestDecryptAndVerySign(t *testing.T) {
by, err := client.DecryptAndVerySign(V1DATA, V1SIGN)
if err != nil {
t.Logf("解密错误 err : %+v", err)
}
if string(by) != STR {
t.Logf("加密数据与期望值不匹配 err : %+v", err)
}
}*/
func TestSendRequest(t *testing.T) {
by, err := client.SendRequest("AUTHORIZE", STR)
if err != nil {
t.Logf("解密错误 err : %+v", err)
}
t.Log(by)
}