提交 cb32610bfee1ea78b3e0d80221553b844a716e76
Merge branch 'dev' into 'master'
Dev See merge request !1
正在显示
15 个修改的文件
包含
670 行增加
和
8 行删除
.gitignore
0 → 100644
README.md
0 → 100644
1 | + | |
2 | +# 命令行 | |
3 | +### 查看参数 | |
4 | +``` | |
5 | +go run main.go -h | |
6 | +``` | |
7 | +### 命令行运行 | |
8 | +``` | |
9 | +go run main.go -key fbb416bfd0a242419e6528f2 -iv 0f6ce46636264d66 -ip http://47.110.250.177:20000/ -bussiness_code AUTHORIZE -ptCode 730088256896503808 -reqBody '{"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":""}' -privateKeyPath /Users/macbook/go/src/socialwork-sdk/main/private.pem -publicKeyPath /Users/macbook/go/src/socialwork-sdk/main/public.pem -errFilePath /Users/macbook/go/src/socialwork-sdk/main/error.txt -resultFilePath /Users/macbook/go/src/socialwork-sdk/main/result.txt | |
10 | +``` | ... | ... |
... | ... | @@ -32,8 +32,6 @@ func aes_CBC_Encrypt(data []byte, key, iv []byte) (string, error) { |
32 | 32 | return "", err |
33 | 33 | } |
34 | 34 | origData := padding([]byte(data), block.BlockSize()) |
35 | - println("block ", block.BlockSize()) | |
36 | - println("block2 ", len(iv)) | |
37 | 35 | blockMode := cipher.NewCBCEncrypter(block, iv) |
38 | 36 | crypted := make([]byte, len(origData)) |
39 | 37 | blockMode.CryptBlocks(crypted, origData) | ... | ... |
encryption_test.go
0 → 100644
1 | +package socialwork_sdk | |
2 | + | |
3 | +import ( | |
4 | + "encoding/json" | |
5 | + "gitlab.workai.com.cn/chenang/socialwork-sdk/model" | |
6 | + "testing" | |
7 | +) | |
8 | + | |
9 | +const ( | |
10 | + KEY = "fbb416bfd0a242419e6528f2" | |
11 | + IV = "0f6ce46636264d66" | |
12 | + //客户私钥 | |
13 | + PRIVATEKEY = `-----BEGIN PRIVATE KEY----- | |
14 | +MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL+HIjm9wYlMx5dR | |
15 | +hCGw9Uw5X1ZKPUfOvKXq/8mIuNVtH2ls6jz1fBlhoSHrYMjxY5t7EPSRZzOLeqGI | |
16 | +7FKbwlHPLAC4cN3njho8TE4Ao7EqipG7L81qHL6Wll/NrziP67+dDROG0ozscmNh | |
17 | +kq0JFxIkxQn3aKGbeEdJbLcLRRM7AgMBAAECgYEAn72Rah89v8nt3eL7FS6GKGDh | |
18 | +hxK8MZvX83oghHIn1roArOlOJDGKo5Ct16B9RJsvvInUBmcPcAow6XFNyUhntGnk | |
19 | +evnBZSPz8SJlwGMTTz/P4ebQURrcup5UejQzmBOSXrIXsrW4Ty0AdvnwM1OB/lmz | |
20 | +tQZyU3xMzK6QbXJkCgECQQDqWeR9/gBwWZLkZBPQASxWbb7NKwyCNN7clzMZv6MN | |
21 | +ea8sR7Zp6cNfPtfcVVTeHRX/sXRhB7inRyLi/ec3dSJBAkEA0TiGYiTv1l5prTCC | |
22 | +PK6lyShDK9SR8ZBcSxO5KsttFeOs3f9l2uU0ddd8fAuLJPm2xjd3RAbnH9dAfEC1 | |
23 | +GXoeewJBAJ/aB0iFnIkGIHNXbEhCtJqTq0VJavPZ2nZ/UCTtGexUJ0+97shZ4qEy | |
24 | +PY2WSxhioKHTyn1xBdxcYoiRBklGxcECQAqDOZVi3744vjyajGC6MdBauo1QQAkQ | |
25 | +ROLs2cgBsrh/2SbKd3a5P5qQOkwNVG+GMJ3jGZYMdr6N1UqpAbCHB1MCQH1aSvf2 | |
26 | ++CXW9fbkUz+qyjIWLN0pDyI+uh+zAHRRs9sL5UVOLfyU03W3120bUL7aekrbynP8 | |
27 | +1+ihe8QolWZgvUk= | |
28 | +-----END PRIVATE KEY-----` | |
29 | + //平台公钥 | |
30 | + PUBLICKEY = `-----BEGIN PUBLIC KEY----- | |
31 | +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHk0VRd3+CqwUHA2jC4dzrqe7/ | |
32 | +pjX8BTbC7T7DnzAGO7iN09kf2abbzudLTM+xbOKr2wSTLkhffBhycZ4zlf3PuVu/ | |
33 | +KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm | |
34 | +3YZBKCNST3LB1JNSeQIDAQAB | |
35 | +-----END PUBLIC KEY-----` | |
36 | + IP = "http://47.110.250.177:20000/" | |
37 | + //IP = "http://127.0.0.1:51393/" | |
38 | + PTCODE = "730088256896503808" | |
39 | + 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":""}` | |
40 | + | |
41 | + V1DATA = "Wxy8h961GO12QmdOdwOYaUZdy6P+o67Olid6YbbjP+SiZNKYofmbQ33eyixsWXIP33sLIrrUrYZ/BNd1+iC8Bng9itBpIcJEfO7fJX9+8Sgp+5hORLESdPRoiyIjeQMX1JKpBk0Uiu7eSsxRRepi33oMi1+580LtFa91lc44PAwnrAEPoTZbEpPQQQmNPrGM0DzmZRUxEIT/SajlwoNg34DvKrGpsb2g8GZ7wUR8GuTOYUg2odF8WjTWNj2GWuzCUw8WPN8FGXdgTzRMn0glivn5SizGmJn0oOJZxo4JRG0Q6h0hV3xi8nPtvwjyOdy0Wspjcd4jQny1jaOKCaPg/5CRLWdmQKLE9d7UhSyQoQ6jzNxEkd/r7vAbtuvRfwvB6zN7NKODjVc/kJf7qovou8u6k2xBGQ7C1CT8wULjqRy3bAYfJ4A5YYWIwtMPJ/l1swlEYsalq5M4Y1g5RjnX1auMczdhnTCOzNeXm2tTJSQ=" | |
42 | + V1SIGN = "qTxPJ0t4vW6cMIMYw5vQukG+BnsUY0ku5S1h9TM/IHqJVa0VU5Q7FXxgy0I6T6R12jDZ37+R9RxeEBzO5Fc3rfMWQQfcfGfLgRsbhHSjF0In9T72QHKmzn2upArfCArNlDJh+tC3FvTG9BTMfztlLRlXmVJJ7oTqgJDcZ4m5IqU=" | |
43 | +) | |
44 | + | |
45 | +var client *OrderClient | |
46 | + | |
47 | +func init() { | |
48 | + client = NewOrderClient(KEY, IV, PRIVATEKEY, PUBLICKEY, IP,PTCODE) | |
49 | +} | |
50 | + | |
51 | +func TestCheckParams(t *testing.T) { | |
52 | + 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"}` | |
53 | + if err := checkParams("AUTHORIZE", b); err != nil { | |
54 | + t.Logf("AUTHORIZE err : %+v", err) | |
55 | + } | |
56 | + | |
57 | + 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"}}` | |
58 | + if err := checkParams("CREATEORDER", b); err != nil { | |
59 | + t.Logf("CREATEORDER err : %+v", err) | |
60 | + } | |
61 | + | |
62 | + 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":""}]}` | |
63 | + if err := checkParams("ADDFREEDOMEEMP", b); err != nil { | |
64 | + t.Logf("ADDFREEDOMEEMP err : %+v", err) | |
65 | + } | |
66 | + | |
67 | + b = `{"id":"690313836787404802","file_type":"id_card_front_image","content":"6ZmE5Lu25YaF5a65","trace_no":"dsdsds"}` | |
68 | + if err := checkParams("UPLOADATTACHMENT", b); err != nil { | |
69 | + t.Logf("UPLOADATTACHMENT err : %+v", err) | |
70 | + } | |
71 | + | |
72 | + b = `{"id":"695762134566440960","file_type":"id_card_front_image","url":"http://hbimg.b0.upaiyun.com/32f065b3afb3fb36b75a5cbc9034s051b1050e1e6b6e199-Ml6q9F_fw320","trace_no":"dsdsds"}` | |
73 | + if err := checkParams("UPLOADATTACHMENTBYURL", b); err != nil { | |
74 | + t.Logf("UPLOADATTACHMENTBYURL err : %+v", err) | |
75 | + } | |
76 | + | |
77 | + b = `{"id":"705537141886685184"}` | |
78 | + if err := checkParams("ORDERINFO", b); err != nil { | |
79 | + t.Logf("ORDERINFO err : %+v", err) | |
80 | + } | |
81 | + | |
82 | + b = `{"id":"719706386803462144"}` | |
83 | + if err := checkParams("FREEDOMEMOSTATUS", b); err != nil { | |
84 | + t.Logf("FREEDOMEMOSTATUS err : %+v", err) | |
85 | + } | |
86 | + | |
87 | + b = `{"id":"30207117494289"}` | |
88 | + if err := checkParams("SUBACCOUNTBALANCE", b); err != nil { | |
89 | + t.Logf("SUBACCOUNTBALANCE err : %+v", err) | |
90 | + } | |
91 | + | |
92 | + 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"]}` | |
93 | + if err := checkParams("UPDATEORDERDETAIL", b); err != nil { | |
94 | + t.Logf("UPDATEORDERDETAIL err : %+v", err) | |
95 | + } | |
96 | + | |
97 | + b = `{"id":"700814624890556416"}` | |
98 | + if err := checkParams("EXISTRECEIPT", b); err != nil { | |
99 | + t.Logf("EXISTRECEIPT err : %+v", err) | |
100 | + } | |
101 | + | |
102 | + b = `{"file_id":[],"type":"pa","order_id":"700814624890556416"}` | |
103 | + if err := checkParams("DOWNLOADRECEIPT", b); err != nil { | |
104 | + t.Logf("DOWNLOADRECEIPT err : %+v", err) | |
105 | + } | |
106 | + | |
107 | + b = `{"id":"728622438832672768","bank":"银行民称","recharge_date":1639639779,"serial_no":"76547654765","setting_status":false,"pt_code":""}` | |
108 | + if err := checkParams("PAYORDER", b); err != nil { | |
109 | + t.Logf("PAYORDER err : %+v", err) | |
110 | + } | |
111 | + | |
112 | + 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":""}` | |
113 | + if err := checkParams("PAYORDERV1", b); err != nil { | |
114 | + t.Logf("PAYORDERV1 err : %+v", err) | |
115 | + } | |
116 | + | |
117 | + b = `{"filter":{"mobile":"13301169755"}}` | |
118 | + if err := checkParams("USERINFO", b); err != nil { | |
119 | + t.Logf("USERINFO err : %+v", err) | |
120 | + } | |
121 | + | |
122 | + b = `{"user_id":"705485356060905472","mobile":"18881652932"}` | |
123 | + if err := checkParams("UPDATEMOBILE", b); err != nil { | |
124 | + t.Logf("UPDATEMOBILE err : %+v", err) | |
125 | + } | |
126 | + | |
127 | + 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"}` | |
128 | + if err := checkParams("CREATEEMPLOYMENTPOOL", b); err != nil { | |
129 | + t.Logf("CREATEEMPLOYMENTPOOL err : %+v", err) | |
130 | + } | |
131 | +} | |
132 | + | |
133 | +func checkParams(businessCode, reqBody string) error { | |
134 | + switch businessCode { | |
135 | + case "AUTHORIZE": | |
136 | + var authorize model.Authorize | |
137 | + if err := json.Unmarshal([]byte(reqBody), &authorize); err != nil { | |
138 | + return err | |
139 | + } | |
140 | + return nil | |
141 | + case "CREATEORDER": | |
142 | + var createOrder model.CreateOrder | |
143 | + if err := json.Unmarshal([]byte(reqBody), &createOrder); err != nil { | |
144 | + return err | |
145 | + } | |
146 | + return nil | |
147 | + case "ADDFREEDOMEEMP": | |
148 | + var freedomEmps model.FreedomEmps | |
149 | + if err := json.Unmarshal([]byte(reqBody), &freedomEmps); err != nil { | |
150 | + return err | |
151 | + } | |
152 | + return nil | |
153 | + case "UPLOADATTACHMENT": | |
154 | + var uploadFreedomEmps model.UploadFreedomEmps | |
155 | + if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmps); err != nil { | |
156 | + return err | |
157 | + } | |
158 | + return nil | |
159 | + case "UPLOADATTACHMENTBYURL": | |
160 | + var uploadFreedomEmpsByUrl model.UploadFreedomEmpsByUrl | |
161 | + if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmpsByUrl); err != nil { | |
162 | + return err | |
163 | + } | |
164 | + return nil | |
165 | + case "ORDERINFO": | |
166 | + var simpleOrderInfo model.SimpleOrderInfo | |
167 | + if err := json.Unmarshal([]byte(reqBody), &simpleOrderInfo); err != nil { | |
168 | + return err | |
169 | + } | |
170 | + return nil | |
171 | + case "FREEDOMEMOSTATUS": | |
172 | + var freedomEmpStatus model.FreedomEmpStatus | |
173 | + if err := json.Unmarshal([]byte(reqBody), &freedomEmpStatus); err != nil { | |
174 | + return err | |
175 | + } | |
176 | + return nil | |
177 | + case "SUBACCOUNTBALANCE": | |
178 | + var subAccountBalance model.SubAccountBalance | |
179 | + if err := json.Unmarshal([]byte(reqBody), &subAccountBalance); err != nil { | |
180 | + return err | |
181 | + } | |
182 | + return nil | |
183 | + case "UPDATEORDERDETAIL": | |
184 | + var updateOrderDetail model.UpdateOrderDetail | |
185 | + if err := json.Unmarshal([]byte(reqBody), &updateOrderDetail); err != nil { | |
186 | + return err | |
187 | + } | |
188 | + return nil | |
189 | + case "EXISTRECEIPT": | |
190 | + var receipt model.Receipt | |
191 | + if err := json.Unmarshal([]byte(reqBody), &receipt); err != nil { | |
192 | + return err | |
193 | + } | |
194 | + return nil | |
195 | + case "DOWNLOADRECEIPT": | |
196 | + var downloadReceipt model.DownloadReceipt | |
197 | + if err := json.Unmarshal([]byte(reqBody), &downloadReceipt); err != nil { | |
198 | + return err | |
199 | + } | |
200 | + return nil | |
201 | + case "PAYORDER": | |
202 | + var payOrder model.PayOrder | |
203 | + if err := json.Unmarshal([]byte(reqBody), &payOrder); err != nil { | |
204 | + return err | |
205 | + } | |
206 | + return nil | |
207 | + case "USERINFO": | |
208 | + var getUserInfo model.GetUserInfo | |
209 | + if err := json.Unmarshal([]byte(reqBody), &getUserInfo); err != nil { | |
210 | + return err | |
211 | + } | |
212 | + return nil | |
213 | + case "PAYORDERV1": | |
214 | + var mergeCreateOrder model.MergeCreateOrder | |
215 | + if err := json.Unmarshal([]byte(reqBody), &mergeCreateOrder); err != nil { | |
216 | + return err | |
217 | + } | |
218 | + return nil | |
219 | + case "UPDATEMOBILE": | |
220 | + var updateMobile model.UpdateMobile | |
221 | + if err := json.Unmarshal([]byte(reqBody), &updateMobile); err != nil { | |
222 | + return err | |
223 | + } | |
224 | + return nil | |
225 | + | |
226 | + case "CREATEEMPLOYMENTPOOL": | |
227 | + var createEmploymentPool model.CreateEmploymentPool | |
228 | + if err := json.Unmarshal([]byte(reqBody), &createEmploymentPool); err != nil { | |
229 | + return err | |
230 | + } | |
231 | + return nil | |
232 | + } | |
233 | + return nil | |
234 | +} | |
235 | + | |
236 | +func TestEncryption(t *testing.T) { | |
237 | + data, sign, err := client.EncryptAndSign([]byte(STR)) | |
238 | + if err != nil { | |
239 | + t.Logf("加密和签名错误 err : %+v", err) | |
240 | + } | |
241 | + if data != V1DATA { | |
242 | + t.Logf("加密数据与期望值不匹配 err : %+v", err) | |
243 | + } | |
244 | + | |
245 | + if sign != V1SIGN { | |
246 | + t.Logf("签名数据与期望值不匹配 err : %+v", err) | |
247 | + } | |
248 | + | |
249 | +} | |
250 | + | |
251 | +/*func TestDecryptAndVerySign(t *testing.T) { | |
252 | + by, err := client.DecryptAndVerySign(V1DATA, V1SIGN) | |
253 | + if err != nil { | |
254 | + t.Logf("解密错误 err : %+v", err) | |
255 | + } | |
256 | + if string(by) != STR { | |
257 | + t.Logf("加密数据与期望值不匹配 err : %+v", err) | |
258 | + } | |
259 | + | |
260 | +}*/ | |
261 | + | |
262 | +func TestSendRequest(t *testing.T) { | |
263 | + by, err := client.SendRequest("AUTHORIZE", STR) | |
264 | + if err != nil { | |
265 | + t.Logf("解密错误 err : %+v", err) | |
266 | + } | |
267 | + t.Log(by) | |
268 | + | |
269 | +} | ... | ... |
... | ... | @@ -83,9 +83,6 @@ func makeHttpRequestV4(method, url string, headers map[string]string, entity map |
83 | 83 | Jar: jar, |
84 | 84 | } |
85 | 85 | } |
86 | - // client.Transport = tr | |
87 | - | |
88 | - fmt.Printf("xuht================Request: %+v\n", *req) | |
89 | 86 | res, err := client.Do(req) |
90 | 87 | if err != nil { |
91 | 88 | fmt.Println("faild to do the request with error ", err) | ... | ... |
main/main.go
0 → 100644
1 | +package main | |
2 | + | |
3 | +import ( | |
4 | + "bufio" | |
5 | + "crypto/rand" | |
6 | + "crypto/rsa" | |
7 | + "crypto/x509" | |
8 | + "encoding/pem" | |
9 | + "flag" | |
10 | + socialwork_sdk "gitlab.workai.com.cn/chenang/socialwork-sdk" | |
11 | + "io/ioutil" | |
12 | + "os" | |
13 | +) | |
14 | + | |
15 | +/*func init(){ | |
16 | + var bits int | |
17 | + flag.IntVar(&bits, "b", 1024, "密钥长度,默认为1024位") | |
18 | + flag.Parse() | |
19 | + | |
20 | + if err := GenRsaKey(bits); err != nil { | |
21 | + log.Fatal("密钥文件生成失败!") | |
22 | + } | |
23 | + log.Println("密钥文件生成成功!") | |
24 | +} | |
25 | +*/ | |
26 | +func main() { | |
27 | + var key, iv, privateKeyPath, publicKeyPath, ip, bussinessCode, ptCode, reqBody, errFilePath, resultFilePath string | |
28 | + flag.StringVar(&key, "key", "", "key,验证签名使用的key") | |
29 | + flag.StringVar(&iv, "iv", "", "iv,加密使用的偏移量") | |
30 | + flag.StringVar(&privateKeyPath, "privateKeyPath", "", "privateKeyPath,私钥文件所在位置(.pem文件)") | |
31 | + flag.StringVar(&publicKeyPath, "publicKeyPath", "", "publicKeyPath,平台公钥文件所在位置(.pem文件)") | |
32 | + flag.StringVar(&ip, "ip", "", "ip,访问地址,如:http://47.110.250.177:20000/") | |
33 | + flag.StringVar(&bussinessCode, "bussiness_code", "", "bussiness_code,访问接口的bussiness_code参数") | |
34 | + flag.StringVar(&ptCode, "ptCode", "", "ptCode,访问接口的ptcode参数") | |
35 | + flag.StringVar(&reqBody, "reqBody", "", "reqBody,需要加密的数据(json格式)") | |
36 | + flag.StringVar(&errFilePath, "errFilePath", "", "errFilePath,错误信息写入的文件地址") | |
37 | + flag.StringVar(&resultFilePath, "resultFilePath", "", "resultFilePath,返回资源写入的文件地址") | |
38 | + flag.Parse() | |
39 | + if key == "" || iv == "" || privateKeyPath == "" || publicKeyPath == "" || ip == "" || bussinessCode == "" || ptCode == "" || reqBody == "" || resultFilePath == "" || errFilePath == "" { | |
40 | + os.Exit(1) | |
41 | + } | |
42 | + var err error | |
43 | + var publicKey, privateKey []byte | |
44 | + var req string | |
45 | + var file, fd *os.File | |
46 | + fd, err = os.OpenFile(errFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) | |
47 | + if err != nil { | |
48 | + os.Exit(1) | |
49 | + } | |
50 | + defer fd.Close() | |
51 | + defer func() { | |
52 | + write := bufio.NewWriter(fd) | |
53 | + write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | |
54 | + write.Flush() | |
55 | + }() | |
56 | + | |
57 | + publicKey, err = ioutil.ReadFile(publicKeyPath) | |
58 | + if err != nil { | |
59 | + return | |
60 | + } | |
61 | + privateKey, err = ioutil.ReadFile(privateKeyPath) | |
62 | + if err != nil { | |
63 | + return | |
64 | + } | |
65 | + | |
66 | + client := socialwork_sdk.NewOrderClient(key, iv, string(privateKey), string(publicKey), ip, ptCode) | |
67 | + req, err = client.SendRequest(bussinessCode, reqBody) | |
68 | + if err != nil { | |
69 | + return | |
70 | + } else { | |
71 | + file, err = os.Create(resultFilePath) | |
72 | + if err != nil { | |
73 | + return | |
74 | + } | |
75 | + defer file.Close() | |
76 | + | |
77 | + file.WriteString(req) | |
78 | + return | |
79 | + } | |
80 | +} | |
81 | + | |
82 | +func GenRsaKey(bits int) error { | |
83 | + // 生成私钥文件 | |
84 | + privateKey, err := rsa.GenerateKey(rand.Reader, bits) | |
85 | + if err != nil { | |
86 | + return err | |
87 | + } | |
88 | + derStream := x509.MarshalPKCS1PrivateKey(privateKey) | |
89 | + block := &pem.Block{ | |
90 | + Type: "私钥", | |
91 | + Bytes: derStream, | |
92 | + } | |
93 | + file, err := os.Create("private.pem") | |
94 | + if err != nil { | |
95 | + return err | |
96 | + } | |
97 | + err = pem.Encode(file, block) | |
98 | + if err != nil { | |
99 | + return err | |
100 | + } | |
101 | + // 生成公钥文件 | |
102 | + publicKey := &privateKey.PublicKey | |
103 | + derPkix, err := x509.MarshalPKIXPublicKey(publicKey) | |
104 | + if err != nil { | |
105 | + return err | |
106 | + } | |
107 | + block = &pem.Block{ | |
108 | + Type: "公钥", | |
109 | + Bytes: derPkix, | |
110 | + } | |
111 | + file, err = os.Create("public.pem") | |
112 | + if err != nil { | |
113 | + return err | |
114 | + } | |
115 | + err = pem.Encode(file, block) | |
116 | + if err != nil { | |
117 | + return err | |
118 | + } | |
119 | + return nil | |
120 | +} | ... | ... |
model/account.go
0 → 100644
model/authorize.go
0 → 100644
1 | +package model | |
2 | + | |
3 | +type Authorize struct { | |
4 | + ResponseType string `json:"response_type"` | |
5 | + ClientId string `json:"client_id"` | |
6 | + RedirectUri string `json:"redirect_uri"` | |
7 | + State string `json:"state"` | |
8 | + Scope string `json:"scope"` | |
9 | + UserMobile string `json:"user_mobile"` | |
10 | + UserName string `json:"user_name"` | |
11 | + Callback string `json:"callback"` | |
12 | + Certification string `json:"certification"` | |
13 | + Ptcode string `json:"ptcode"` | |
14 | + PathType string `json:"path_type"` | |
15 | + Path string `json:"path"` | |
16 | +} | |
17 | + | |
18 | +type Receipt struct { | |
19 | + Id string `json:"id"` | |
20 | +} | ... | ... |
model/employment_pool.go
0 → 100644
model/freedom_emp.go
0 → 100644
1 | +package model | |
2 | + | |
3 | +type FreedomEmps struct { | |
4 | + Id string `json:"id"` | |
5 | + Items []*FreedomEmp `json:"items"` | |
6 | +} | |
7 | + | |
8 | +type FreedomEmp struct { | |
9 | + UserName string `json:"user_name"` | |
10 | + UserMobile string `json:"user_mobile"` | |
11 | + IdCardNo string `json:"id_card_no"` | |
12 | + BankName string `json:"bank_name"` | |
13 | + BankCard string `json:"bank_card"` | |
14 | + TotalSalary string `json:"total_salary"` | |
15 | + Comment string `json:"comment"` | |
16 | + JobName string `json:"job_name"` | |
17 | + BeginTime int64 `json:"begin_time"` | |
18 | + EndTime int64 `json:"end_time"` | |
19 | + JobType string `json:"job_type"` | |
20 | + WorkPlace string `json:"work_place"` | |
21 | + SalaryUnit string `json:"salary_unit"` | |
22 | + Salary string `json:"salary"` | |
23 | + ConfirmType string `json:"confirm_type"` | |
24 | + OpenAccountBank string `json:"open_account_bank"` | |
25 | + OpenAccountPlace string `json:"open_account_place"` | |
26 | + OpenBankNo string `json:"open_bank_no"` | |
27 | + IndustryCode string `json:"industry_code"` | |
28 | + Extra string `json:"extra"` | |
29 | + BankPaymentId string `json:"bank_payment_id"` | |
30 | + WorkLoad string `json:"work_load"` | |
31 | + IntervalPrice string `json:"interval_price"` | |
32 | + RealTotalSalary string `json:"real_total_salary"` | |
33 | +} | |
34 | + | |
35 | + | |
36 | +type UploadFreedomEmps struct { | |
37 | + Id string `json:"id"` | |
38 | + FileType string `json:"file_type"` | |
39 | + Content string `json:"content"` | |
40 | + TraceNo string `json:"trace_no"` | |
41 | +} | |
42 | + | |
43 | +type UploadFreedomEmpsByUrl struct { | |
44 | + Id string `json:"id"` | |
45 | + FileType string `json:"file_type"` | |
46 | + Url string `json:"url"` | |
47 | + TraceNo string `json:"trace_no"` | |
48 | +} | |
49 | + | |
50 | +type FreedomEmpStatus struct { | |
51 | + Id string `json:"id"` | |
52 | +} | |
53 | + | |
54 | +type UpdateOrderDetail struct { | |
55 | + OrderId string `json:"order_id"` | |
56 | + DetailId string `json:"detail_id"` | |
57 | + UserName string `json:"user_name"` | |
58 | + UserMobile string `json:"user_mobile"` | |
59 | + UserIdCard string `json:"user_id_card"` | |
60 | + BankName string `json:"bank_name"` | |
61 | + BankCard string `json:"bank_card"` | |
62 | + UpdateFields []string `json:"update_fields"` | |
63 | +} | ... | ... |
model/order.go
0 → 100644
1 | +package model | |
2 | + | |
3 | +type CreateOrder struct { | |
4 | + Items *ExternalCreateOrder `json:"items,omitempty"` | |
5 | +} | |
6 | + | |
7 | +type ExternalCreateOrder struct { | |
8 | + Name string `json:"name"` | |
9 | + CustomerName string `json:"customer_name"` | |
10 | + ServiceContractNo string `json:"service_contract_no"` | |
11 | + BillMonth int64 `json:"bill_month"` | |
12 | + PayerObjectType string `json:"payer_object_type"` | |
13 | + PayerObjectName string `json:"payer_object_name"` | |
14 | + ElectronContractTemplateName string `json:"electron_contract_template_name"` | |
15 | + SettlementOrgId string `json:"settlement_org_id"` | |
16 | + HasAutoCreate string `json:"has_auto_create"` | |
17 | + PayerName string `json:"payer_name"` | |
18 | + PayerMobile string `json:"payer_mobile"` | |
19 | + ProvideMode string `json:"provide_mode"` | |
20 | + Callback string `json:"callback"` | |
21 | +} | |
22 | + | |
23 | +type SimpleOrderInfo struct { | |
24 | + Id string `json:"id"` | |
25 | +} | |
26 | + | |
27 | +type PayOrder struct { | |
28 | + Id string `json:"id"` | |
29 | + Bank string `json:"bank"` | |
30 | + RechargeDate int64 `json:"recharge_date"` | |
31 | + SerialNo string `json:"serial_no"` | |
32 | + SettingStatus bool `json:"setting_status"` | |
33 | + PtCode string `json:"pt_code"` | |
34 | +} | |
35 | + | |
36 | +type MergeCreateOrder struct { | |
37 | + Name string `json:"name"` | |
38 | + ServiceContractNo string `json:"service_contract_no"` | |
39 | + BillMonth int64 `json:"bill_month"` | |
40 | + PayerObjectType string `json:"payer_object_type"` | |
41 | + SettlementOrgId string `json:"settlement_org_id"` | |
42 | + PayerName string `json:"payer_name"` | |
43 | + PayerMobile string `json:"payer_mobile"` | |
44 | + ProvideMode string `json:"provide_mode"` | |
45 | + Details []*FreedomEmp `json:"details"` | |
46 | + Callback string `son:"callback"` | |
47 | + SettingStatus bool `json:"setting_status"` | |
48 | + PtCode string `json:"pt_code"` | |
49 | +} | ... | ... |
model/user.go
0 → 100644
... | ... | @@ -21,13 +21,14 @@ func HelloWorld() { |
21 | 21 | fmt.Println("欢迎使用小爱,socialwork-sdk") |
22 | 22 | } |
23 | 23 | |
24 | -func NewOrderClient(key, iv, customerPrivateKey, publicKey, ip string) *OrderClient { | |
24 | +func NewOrderClient(key, iv, customerPrivateKey, publicKey, ip, ptCode string) *OrderClient { | |
25 | 25 | return &OrderClient{ |
26 | 26 | Key: key, |
27 | 27 | IV: iv, |
28 | 28 | PublicKey: publicKey, |
29 | 29 | CustomerPrivateKey: customerPrivateKey, |
30 | 30 | IP: ip, |
31 | + PtCode: ptCode, | |
31 | 32 | } |
32 | 33 | } |
33 | 34 | |
... | ... | @@ -79,7 +80,6 @@ func (o *OrderClient) SendRequest(businessCode, reqBody string) (string, error) |
79 | 80 | PtCode: o.PtCode, |
80 | 81 | BusinessCode: businessCode, |
81 | 82 | } |
82 | - | |
83 | 83 | _orderModel, err := json.Marshal(orderModel) |
84 | 84 | if err != nil { |
85 | 85 | return "", err |
... | ... | @@ -99,5 +99,104 @@ func (o *OrderClient) SendRequest(businessCode, reqBody string) (string, error) |
99 | 99 | } |
100 | 100 | |
101 | 101 | func (o *OrderClient) checkParams(businessCode, reqBody string) error { |
102 | + switch businessCode { | |
103 | + case "AUTHORIZE": | |
104 | + var authorize model.Authorize | |
105 | + if err := json.Unmarshal([]byte(reqBody), &authorize); err != nil { | |
106 | + return err | |
107 | + } | |
108 | + return nil | |
109 | + case "CREATEORDER": | |
110 | + var createOrder model.CreateOrder | |
111 | + if err := json.Unmarshal([]byte(reqBody), &createOrder); err != nil { | |
112 | + return err | |
113 | + } | |
114 | + return nil | |
115 | + case "ADDFREEDOMEEMP": | |
116 | + var freedomEmps model.FreedomEmps | |
117 | + if err := json.Unmarshal([]byte(reqBody), &freedomEmps); err != nil { | |
118 | + return err | |
119 | + } | |
120 | + return nil | |
121 | + case "UPLOADATTACHMENT": | |
122 | + var uploadFreedomEmps model.UploadFreedomEmps | |
123 | + if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmps); err != nil { | |
124 | + return err | |
125 | + } | |
126 | + return nil | |
127 | + case "UPLOADATTACHMENTBYURL": | |
128 | + var uploadFreedomEmpsByUrl model.UploadFreedomEmpsByUrl | |
129 | + if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmpsByUrl); err != nil { | |
130 | + return err | |
131 | + } | |
132 | + return nil | |
133 | + case "ORDERINFO": | |
134 | + var simpleOrderInfo model.SimpleOrderInfo | |
135 | + if err := json.Unmarshal([]byte(reqBody), &simpleOrderInfo); err != nil { | |
136 | + return err | |
137 | + } | |
138 | + return nil | |
139 | + case "FREEDOMEMOSTATUS": | |
140 | + var freedomEmpStatus model.FreedomEmpStatus | |
141 | + if err := json.Unmarshal([]byte(reqBody), &freedomEmpStatus); err != nil { | |
142 | + return err | |
143 | + } | |
144 | + return nil | |
145 | + case "SUBACCOUNTBALANCE": | |
146 | + var subAccountBalance model.SubAccountBalance | |
147 | + if err := json.Unmarshal([]byte(reqBody), &subAccountBalance); err != nil { | |
148 | + return err | |
149 | + } | |
150 | + return nil | |
151 | + case "UPDATEORDERDETAIL": | |
152 | + var updateOrderDetail model.UpdateOrderDetail | |
153 | + if err := json.Unmarshal([]byte(reqBody), &updateOrderDetail); err != nil { | |
154 | + return err | |
155 | + } | |
156 | + return nil | |
157 | + case "EXISTRECEIPT": | |
158 | + var receipt model.Receipt | |
159 | + if err := json.Unmarshal([]byte(reqBody), &receipt); err != nil { | |
160 | + return err | |
161 | + } | |
162 | + return nil | |
163 | + case "DOWNLOADRECEIPT": | |
164 | + var downloadReceipt model.DownloadReceipt | |
165 | + if err := json.Unmarshal([]byte(reqBody), &downloadReceipt); err != nil { | |
166 | + return err | |
167 | + } | |
168 | + return nil | |
169 | + case "PAYORDER": | |
170 | + var payOrder model.PayOrder | |
171 | + if err := json.Unmarshal([]byte(reqBody), &payOrder); err != nil { | |
172 | + return err | |
173 | + } | |
174 | + return nil | |
175 | + case "USERINFO": | |
176 | + var getUserInfo model.GetUserInfo | |
177 | + if err := json.Unmarshal([]byte(reqBody), &getUserInfo); err != nil { | |
178 | + return err | |
179 | + } | |
180 | + return nil | |
181 | + case "PAYORDERV1": | |
182 | + var mergeCreateOrder model.MergeCreateOrder | |
183 | + if err := json.Unmarshal([]byte(reqBody), &mergeCreateOrder); err != nil { | |
184 | + return err | |
185 | + } | |
186 | + return nil | |
187 | + case "UPDATEMOBILE": | |
188 | + var updateMobile model.UpdateMobile | |
189 | + if err := json.Unmarshal([]byte(reqBody), &updateMobile); err != nil { | |
190 | + return err | |
191 | + } | |
192 | + return nil | |
193 | + | |
194 | + case "CREATEEMPLOYMENTPOOL": | |
195 | + var createEmploymentPool model.CreateEmploymentPool | |
196 | + if err := json.Unmarshal([]byte(reqBody), &createEmploymentPool); err != nil { | |
197 | + return err | |
198 | + } | |
199 | + return nil | |
200 | + } | |
102 | 201 | return nil |
103 | 202 | } | ... | ... |
请
注册
或
登录
后发表评论