正在显示
7 个修改的文件
包含
171 行增加
和
24 行删除
... | ... | @@ -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) | ... | ... |
... | ... | @@ -35,6 +35,7 @@ KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm |
35 | 35 | -----END PUBLIC KEY-----` |
36 | 36 | IP = "http://47.110.250.177:20000/" |
37 | 37 | //IP = "http://127.0.0.1:51393/" |
38 | + PTCODE = "730088256896503808" | |
38 | 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":""}` |
39 | 40 | |
40 | 41 | V1DATA = "Wxy8h961GO12QmdOdwOYaUZdy6P+o67Olid6YbbjP+SiZNKYofmbQ33eyixsWXIP33sLIrrUrYZ/BNd1+iC8Bng9itBpIcJEfO7fJX9+8Sgp+5hORLESdPRoiyIjeQMX1JKpBk0Uiu7eSsxRRepi33oMi1+580LtFa91lc44PAwnrAEPoTZbEpPQQQmNPrGM0DzmZRUxEIT/SajlwoNg34DvKrGpsb2g8GZ7wUR8GuTOYUg2odF8WjTWNj2GWuzCUw8WPN8FGXdgTzRMn0glivn5SizGmJn0oOJZxo4JRG0Q6h0hV3xi8nPtvwjyOdy0Wspjcd4jQny1jaOKCaPg/5CRLWdmQKLE9d7UhSyQoQ6jzNxEkd/r7vAbtuvRfwvB6zN7NKODjVc/kJf7qovou8u6k2xBGQ7C1CT8wULjqRy3bAYfJ4A5YYWIwtMPJ/l1swlEYsalq5M4Y1g5RjnX1auMczdhnTCOzNeXm2tTJSQ=" |
... | ... | @@ -44,7 +45,7 @@ KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm |
44 | 45 | var client *OrderClient |
45 | 46 | |
46 | 47 | func init() { |
47 | - client = NewOrderClient(KEY, IV, PRIVATEKEY, PUBLICKEY, IP) | |
48 | + client = NewOrderClient(KEY, IV, PRIVATEKEY, PUBLICKEY, IP,PTCODE) | |
48 | 49 | } |
49 | 50 | |
50 | 51 | func TestCheckParams(t *testing.T) { | ... | ... |
... | ... | @@ -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 | + | |
16 | +/*func init(){ | |
17 | + var bits int | |
18 | + flag.IntVar(&bits, "b", 1024, "密钥长度,默认为1024位") | |
19 | + flag.Parse() | |
20 | + | |
21 | + if err := GenRsaKey(bits); err != nil { | |
22 | + log.Fatal("密钥文件生成失败!") | |
23 | + } | |
24 | + log.Println("密钥文件生成成功!") | |
25 | +} | |
26 | +*/ | |
27 | +func main() { | |
28 | + var key string | |
29 | + var iv string | |
30 | + var privateKeyPath string | |
31 | + var publicKeyPath string | |
32 | + var ip string | |
33 | + var bussinessCode string | |
34 | + var ptCode string | |
35 | + var reqBody string | |
36 | + var errFilePath string | |
37 | + var resultFilePath string | |
38 | + flag.StringVar(&key, "key", "", "key") | |
39 | + flag.StringVar(&iv, "iv", "", "iv") | |
40 | + flag.StringVar(&privateKeyPath, "privateKeyPath", "", "privateKeyPath") | |
41 | + flag.StringVar(&publicKeyPath, "publicKeyPath", "", "publicKeyPath") | |
42 | + flag.StringVar(&ip, "ip", "", "ip") | |
43 | + flag.StringVar(&bussinessCode, "bussiness_code", "", "bussiness_code") | |
44 | + flag.StringVar(&ptCode, "ptCode", "", "ptCode") | |
45 | + flag.StringVar(&reqBody, "reqBody", "", "reqBody") | |
46 | + flag.StringVar(&errFilePath, "errFilePath", "", "errFilePath") | |
47 | + flag.StringVar(&resultFilePath, "resultFilePath", "", "resultFilePath") | |
48 | + flag.Parse() | |
49 | + | |
50 | + | |
51 | + fd, _ := os.OpenFile(errFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) | |
52 | + defer fd.Close() | |
53 | + | |
54 | + publicKey, err := ioutil.ReadFile(publicKeyPath) | |
55 | + if err != nil { | |
56 | + write := bufio.NewWriter(fd) | |
57 | + write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | |
58 | + write.Flush() | |
59 | + return | |
60 | + } | |
61 | + privateKey, err := ioutil.ReadFile(privateKeyPath) | |
62 | + if err != nil { | |
63 | + write := bufio.NewWriter(fd) | |
64 | + write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | |
65 | + write.Flush() | |
66 | + return | |
67 | + } | |
68 | + | |
69 | + client := socialwork_sdk.NewOrderClient(key, iv, string(privateKey), string(publicKey), ip, ptCode) | |
70 | + req, err := client.SendRequest(bussinessCode, reqBody) | |
71 | + if err != nil { | |
72 | + write := bufio.NewWriter(fd) | |
73 | + write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | |
74 | + write.Flush() | |
75 | + return | |
76 | + } else { | |
77 | + file, err := os.Create(resultFilePath) | |
78 | + defer file.Close() | |
79 | + | |
80 | + if err != nil { | |
81 | + write := bufio.NewWriter(fd) | |
82 | + write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | |
83 | + write.Flush() | |
84 | + return | |
85 | + } | |
86 | + file.WriteString(req) | |
87 | + return | |
88 | + } | |
89 | +} | |
90 | + | |
91 | +func GenRsaKey(bits int) error { | |
92 | + // 生成私钥文件 | |
93 | + privateKey, err := rsa.GenerateKey(rand.Reader, bits) | |
94 | + if err != nil { | |
95 | + return err | |
96 | + } | |
97 | + derStream := x509.MarshalPKCS1PrivateKey(privateKey) | |
98 | + block := &pem.Block{ | |
99 | + Type: "私钥", | |
100 | + Bytes: derStream, | |
101 | + } | |
102 | + file, err := os.Create("private.pem") | |
103 | + if err != nil { | |
104 | + return err | |
105 | + } | |
106 | + err = pem.Encode(file, block) | |
107 | + if err != nil { | |
108 | + return err | |
109 | + } | |
110 | + // 生成公钥文件 | |
111 | + publicKey := &privateKey.PublicKey | |
112 | + derPkix, err := x509.MarshalPKIXPublicKey(publicKey) | |
113 | + if err != nil { | |
114 | + return err | |
115 | + } | |
116 | + block = &pem.Block{ | |
117 | + Type: "公钥", | |
118 | + Bytes: derPkix, | |
119 | + } | |
120 | + file, err = os.Create("public.pem") | |
121 | + if err != nil { | |
122 | + return err | |
123 | + } | |
124 | + err = pem.Encode(file, block) | |
125 | + if err != nil { | |
126 | + return err | |
127 | + } | |
128 | + return nil | |
129 | +} | ... | ... |
main/private.pem
0 → 100644
1 | +-----BEGIN PRIVATE KEY----- | |
2 | +MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL+HIjm9wYlMx5dR | |
3 | +hCGw9Uw5X1ZKPUfOvKXq/8mIuNVtH2ls6jz1fBlhoSHrYMjxY5t7EPSRZzOLeqGI | |
4 | +7FKbwlHPLAC4cN3njho8TE4Ao7EqipG7L81qHL6Wll/NrziP67+dDROG0ozscmNh | |
5 | +kq0JFxIkxQn3aKGbeEdJbLcLRRM7AgMBAAECgYEAn72Rah89v8nt3eL7FS6GKGDh | |
6 | +hxK8MZvX83oghHIn1roArOlOJDGKo5Ct16B9RJsvvInUBmcPcAow6XFNyUhntGnk | |
7 | +evnBZSPz8SJlwGMTTz/P4ebQURrcup5UejQzmBOSXrIXsrW4Ty0AdvnwM1OB/lmz | |
8 | +tQZyU3xMzK6QbXJkCgECQQDqWeR9/gBwWZLkZBPQASxWbb7NKwyCNN7clzMZv6MN | |
9 | +ea8sR7Zp6cNfPtfcVVTeHRX/sXRhB7inRyLi/ec3dSJBAkEA0TiGYiTv1l5prTCC | |
10 | +PK6lyShDK9SR8ZBcSxO5KsttFeOs3f9l2uU0ddd8fAuLJPm2xjd3RAbnH9dAfEC1 | |
11 | +GXoeewJBAJ/aB0iFnIkGIHNXbEhCtJqTq0VJavPZ2nZ/UCTtGexUJ0+97shZ4qEy | |
12 | +PY2WSxhioKHTyn1xBdxcYoiRBklGxcECQAqDOZVi3744vjyajGC6MdBauo1QQAkQ | |
13 | +ROLs2cgBsrh/2SbKd3a5P5qQOkwNVG+GMJ3jGZYMdr6N1UqpAbCHB1MCQH1aSvf2 | |
14 | ++CXW9fbkUz+qyjIWLN0pDyI+uh+zAHRRs9sL5UVOLfyU03W3120bUL7aekrbynP8 | |
15 | +1+ihe8QolWZgvUk= | |
16 | +-----END PRIVATE KEY----- | ... | ... |
main/public.pem
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 |
... | ... | @@ -102,98 +102,98 @@ func (o *OrderClient) checkParams(businessCode, reqBody string) error { |
102 | 102 | switch businessCode { |
103 | 103 | case "AUTHORIZE": |
104 | 104 | var authorize model.Authorize |
105 | - if err := json.Unmarshal([]byte(reqBody),&authorize); err != nil { | |
105 | + if err := json.Unmarshal([]byte(reqBody), &authorize); err != nil { | |
106 | 106 | return err |
107 | 107 | } |
108 | 108 | return nil |
109 | 109 | case "CREATEORDER": |
110 | 110 | var createOrder model.CreateOrder |
111 | - if err := json.Unmarshal([]byte(reqBody),&createOrder); err != nil { | |
111 | + if err := json.Unmarshal([]byte(reqBody), &createOrder); err != nil { | |
112 | 112 | return err |
113 | 113 | } |
114 | 114 | return nil |
115 | 115 | case "ADDFREEDOMEEMP": |
116 | 116 | var freedomEmps model.FreedomEmps |
117 | - if err := json.Unmarshal([]byte(reqBody),&freedomEmps); err != nil { | |
117 | + if err := json.Unmarshal([]byte(reqBody), &freedomEmps); err != nil { | |
118 | 118 | return err |
119 | 119 | } |
120 | 120 | return nil |
121 | 121 | case "UPLOADATTACHMENT": |
122 | 122 | var uploadFreedomEmps model.UploadFreedomEmps |
123 | - if err := json.Unmarshal([]byte(reqBody),&uploadFreedomEmps); err != nil { | |
123 | + if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmps); err != nil { | |
124 | 124 | return err |
125 | 125 | } |
126 | 126 | return nil |
127 | 127 | case "UPLOADATTACHMENTBYURL": |
128 | 128 | var uploadFreedomEmpsByUrl model.UploadFreedomEmpsByUrl |
129 | - if err := json.Unmarshal([]byte(reqBody),&uploadFreedomEmpsByUrl); err != nil { | |
129 | + if err := json.Unmarshal([]byte(reqBody), &uploadFreedomEmpsByUrl); err != nil { | |
130 | 130 | return err |
131 | 131 | } |
132 | 132 | return nil |
133 | 133 | case "ORDERINFO": |
134 | 134 | var simpleOrderInfo model.SimpleOrderInfo |
135 | - if err := json.Unmarshal([]byte(reqBody),&simpleOrderInfo); err != nil { | |
135 | + if err := json.Unmarshal([]byte(reqBody), &simpleOrderInfo); err != nil { | |
136 | 136 | return err |
137 | 137 | } |
138 | 138 | return nil |
139 | 139 | case "FREEDOMEMOSTATUS": |
140 | 140 | var freedomEmpStatus model.FreedomEmpStatus |
141 | - if err := json.Unmarshal([]byte(reqBody),&freedomEmpStatus); err != nil { | |
141 | + if err := json.Unmarshal([]byte(reqBody), &freedomEmpStatus); err != nil { | |
142 | 142 | return err |
143 | 143 | } |
144 | 144 | return nil |
145 | 145 | case "SUBACCOUNTBALANCE": |
146 | 146 | var subAccountBalance model.SubAccountBalance |
147 | - if err := json.Unmarshal([]byte(reqBody),&subAccountBalance); err != nil { | |
147 | + if err := json.Unmarshal([]byte(reqBody), &subAccountBalance); err != nil { | |
148 | 148 | return err |
149 | 149 | } |
150 | 150 | return nil |
151 | 151 | case "UPDATEORDERDETAIL": |
152 | 152 | var updateOrderDetail model.UpdateOrderDetail |
153 | - if err := json.Unmarshal([]byte(reqBody),&updateOrderDetail); err != nil { | |
153 | + if err := json.Unmarshal([]byte(reqBody), &updateOrderDetail); err != nil { | |
154 | 154 | return err |
155 | 155 | } |
156 | 156 | return nil |
157 | 157 | case "EXISTRECEIPT": |
158 | 158 | var receipt model.Receipt |
159 | - if err := json.Unmarshal([]byte(reqBody),&receipt); err != nil { | |
159 | + if err := json.Unmarshal([]byte(reqBody), &receipt); err != nil { | |
160 | 160 | return err |
161 | 161 | } |
162 | 162 | return nil |
163 | 163 | case "DOWNLOADRECEIPT": |
164 | 164 | var downloadReceipt model.DownloadReceipt |
165 | - if err := json.Unmarshal([]byte(reqBody),&downloadReceipt); err != nil { | |
165 | + if err := json.Unmarshal([]byte(reqBody), &downloadReceipt); err != nil { | |
166 | 166 | return err |
167 | 167 | } |
168 | 168 | return nil |
169 | 169 | case "PAYORDER": |
170 | 170 | var payOrder model.PayOrder |
171 | - if err := json.Unmarshal([]byte(reqBody),&payOrder); err != nil { | |
171 | + if err := json.Unmarshal([]byte(reqBody), &payOrder); err != nil { | |
172 | 172 | return err |
173 | 173 | } |
174 | 174 | return nil |
175 | 175 | case "USERINFO": |
176 | 176 | var getUserInfo model.GetUserInfo |
177 | - if err := json.Unmarshal([]byte(reqBody),&getUserInfo); err != nil { | |
177 | + if err := json.Unmarshal([]byte(reqBody), &getUserInfo); err != nil { | |
178 | 178 | return err |
179 | 179 | } |
180 | 180 | return nil |
181 | 181 | case "PAYORDERV1": |
182 | 182 | var mergeCreateOrder model.MergeCreateOrder |
183 | - if err := json.Unmarshal([]byte(reqBody),&mergeCreateOrder); err != nil { | |
183 | + if err := json.Unmarshal([]byte(reqBody), &mergeCreateOrder); err != nil { | |
184 | 184 | return err |
185 | 185 | } |
186 | 186 | return nil |
187 | 187 | case "UPDATEMOBILE": |
188 | 188 | var updateMobile model.UpdateMobile |
189 | - if err := json.Unmarshal([]byte(reqBody),&updateMobile); err != nil { | |
189 | + if err := json.Unmarshal([]byte(reqBody), &updateMobile); err != nil { | |
190 | 190 | return err |
191 | 191 | } |
192 | 192 | return nil |
193 | 193 | |
194 | 194 | case "CREATEEMPLOYMENTPOOL": |
195 | 195 | var createEmploymentPool model.CreateEmploymentPool |
196 | - if err := json.Unmarshal([]byte(reqBody),&createEmploymentPool); err != nil { | |
196 | + if err := json.Unmarshal([]byte(reqBody), &createEmploymentPool); err != nil { | |
197 | 197 | return err |
198 | 198 | } |
199 | 199 | return nil | ... | ... |
请
注册
或
登录
后发表评论