提交 36f526f12608d3d5e89098cc1e0cfba7cf195438

作者 yuyang
1 个父辈 f129d0d1

update

@@ -32,8 +32,6 @@ func aes_CBC_Encrypt(data []byte, key, iv []byte) (string, error) { @@ -32,8 +32,6 @@ func aes_CBC_Encrypt(data []byte, key, iv []byte) (string, error) {
32 return "", err 32 return "", err
33 } 33 }
34 origData := padding([]byte(data), block.BlockSize()) 34 origData := padding([]byte(data), block.BlockSize())
35 - println("block ", block.BlockSize())  
36 - println("block2 ", len(iv))  
37 blockMode := cipher.NewCBCEncrypter(block, iv) 35 blockMode := cipher.NewCBCEncrypter(block, iv)
38 crypted := make([]byte, len(origData)) 36 crypted := make([]byte, len(origData))
39 blockMode.CryptBlocks(crypted, origData) 37 blockMode.CryptBlocks(crypted, origData)
@@ -35,6 +35,7 @@ KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm @@ -35,6 +35,7 @@ KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm
35 -----END PUBLIC KEY-----` 35 -----END PUBLIC KEY-----`
36 IP = "http://47.110.250.177:20000/" 36 IP = "http://47.110.250.177:20000/"
37 //IP = "http://127.0.0.1:51393/" 37 //IP = "http://127.0.0.1:51393/"
  38 + PTCODE = "730088256896503808"
38 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 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 V1DATA = "Wxy8h961GO12QmdOd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,7 +45,7 @@ KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm
44 var client *OrderClient 45 var client *OrderClient
45 46
46 func init() { 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 func TestCheckParams(t *testing.T) { 51 func TestCheckParams(t *testing.T) {
@@ -83,9 +83,6 @@ func makeHttpRequestV4(method, url string, headers map[string]string, entity map @@ -83,9 +83,6 @@ func makeHttpRequestV4(method, url string, headers map[string]string, entity map
83 Jar: jar, 83 Jar: jar,
84 } 84 }
85 } 85 }
86 - // client.Transport = tr  
87 -  
88 - fmt.Printf("xuht================Request: %+v\n", *req)  
89 res, err := client.Do(req) 86 res, err := client.Do(req)
90 if err != nil { 87 if err != nil {
91 fmt.Println("faild to do the request with error ", err) 88 fmt.Println("faild to do the request with error ", err)
  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 +}
  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-----
  1 +-----BEGIN PUBLIC KEY-----
  2 +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHk0VRd3+CqwUHA2jC4dzrqe7/
  3 +pjX8BTbC7T7DnzAGO7iN09kf2abbzudLTM+xbOKr2wSTLkhffBhycZ4zlf3PuVu/
  4 +KmUhzAS0v+cvRYEBdiD+ckC1i80KaGPsiSvKSgJIxEEo1urgsrGJBGP0uBMM50Bm
  5 +3YZBKCNST3LB1JNSeQIDAQAB
  6 +-----END PUBLIC KEY-----
@@ -21,13 +21,14 @@ func HelloWorld() { @@ -21,13 +21,14 @@ func HelloWorld() {
21 fmt.Println("欢迎使用小爱,socialwork-sdk") 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 return &OrderClient{ 25 return &OrderClient{
26 Key: key, 26 Key: key,
27 IV: iv, 27 IV: iv,
28 PublicKey: publicKey, 28 PublicKey: publicKey,
29 CustomerPrivateKey: customerPrivateKey, 29 CustomerPrivateKey: customerPrivateKey,
30 IP: ip, 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,7 +80,6 @@ func (o *OrderClient) SendRequest(businessCode, reqBody string) (string, error)
79 PtCode: o.PtCode, 80 PtCode: o.PtCode,
80 BusinessCode: businessCode, 81 BusinessCode: businessCode,
81 } 82 }
82 -  
83 _orderModel, err := json.Marshal(orderModel) 83 _orderModel, err := json.Marshal(orderModel)
84 if err != nil { 84 if err != nil {
85 return "", err 85 return "", err
@@ -102,98 +102,98 @@ func (o *OrderClient) checkParams(businessCode, reqBody string) error { @@ -102,98 +102,98 @@ func (o *OrderClient) checkParams(businessCode, reqBody string) error {
102 switch businessCode { 102 switch businessCode {
103 case "AUTHORIZE": 103 case "AUTHORIZE":
104 var authorize model.Authorize 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 return err 106 return err
107 } 107 }
108 return nil 108 return nil
109 case "CREATEORDER": 109 case "CREATEORDER":
110 var createOrder model.CreateOrder 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 return err 112 return err
113 } 113 }
114 return nil 114 return nil
115 case "ADDFREEDOMEEMP": 115 case "ADDFREEDOMEEMP":
116 var freedomEmps model.FreedomEmps 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 return err 118 return err
119 } 119 }
120 return nil 120 return nil
121 case "UPLOADATTACHMENT": 121 case "UPLOADATTACHMENT":
122 var uploadFreedomEmps model.UploadFreedomEmps 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 return err 124 return err
125 } 125 }
126 return nil 126 return nil
127 case "UPLOADATTACHMENTBYURL": 127 case "UPLOADATTACHMENTBYURL":
128 var uploadFreedomEmpsByUrl model.UploadFreedomEmpsByUrl 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 return err 130 return err
131 } 131 }
132 return nil 132 return nil
133 case "ORDERINFO": 133 case "ORDERINFO":
134 var simpleOrderInfo model.SimpleOrderInfo 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 return err 136 return err
137 } 137 }
138 return nil 138 return nil
139 case "FREEDOMEMOSTATUS": 139 case "FREEDOMEMOSTATUS":
140 var freedomEmpStatus model.FreedomEmpStatus 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 return err 142 return err
143 } 143 }
144 return nil 144 return nil
145 case "SUBACCOUNTBALANCE": 145 case "SUBACCOUNTBALANCE":
146 var subAccountBalance model.SubAccountBalance 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 return err 148 return err
149 } 149 }
150 return nil 150 return nil
151 case "UPDATEORDERDETAIL": 151 case "UPDATEORDERDETAIL":
152 var updateOrderDetail model.UpdateOrderDetail 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 return err 154 return err
155 } 155 }
156 return nil 156 return nil
157 case "EXISTRECEIPT": 157 case "EXISTRECEIPT":
158 var receipt model.Receipt 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 return err 160 return err
161 } 161 }
162 return nil 162 return nil
163 case "DOWNLOADRECEIPT": 163 case "DOWNLOADRECEIPT":
164 var downloadReceipt model.DownloadReceipt 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 return err 166 return err
167 } 167 }
168 return nil 168 return nil
169 case "PAYORDER": 169 case "PAYORDER":
170 var payOrder model.PayOrder 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 return err 172 return err
173 } 173 }
174 return nil 174 return nil
175 case "USERINFO": 175 case "USERINFO":
176 var getUserInfo model.GetUserInfo 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 return err 178 return err
179 } 179 }
180 return nil 180 return nil
181 case "PAYORDERV1": 181 case "PAYORDERV1":
182 var mergeCreateOrder model.MergeCreateOrder 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 return err 184 return err
185 } 185 }
186 return nil 186 return nil
187 case "UPDATEMOBILE": 187 case "UPDATEMOBILE":
188 var updateMobile model.UpdateMobile 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 return err 190 return err
191 } 191 }
192 return nil 192 return nil
193 193
194 case "CREATEEMPLOYMENTPOOL": 194 case "CREATEEMPLOYMENTPOOL":
195 var createEmploymentPool model.CreateEmploymentPool 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 return err 197 return err
198 } 198 }
199 return nil 199 return nil
注册登录 后发表评论