|
@@ -7,9 +7,12 @@ import (
|
7
|
7
|
"encoding/hex"
|
8
|
8
|
"encoding/json"
|
9
|
9
|
"fmt"
|
|
10
|
+ "io"
|
10
|
11
|
"io/ioutil"
|
11
|
12
|
"math/rand"
|
|
13
|
+ "mime/multipart"
|
12
|
14
|
"net/http"
|
|
15
|
+ "os"
|
13
|
16
|
"strconv"
|
14
|
17
|
"time"
|
15
|
18
|
_ "unsafe"
|
|
@@ -797,6 +800,9 @@ func Gdyb3201(baseParams models.BaseParams, businessParams models.BusinessParams
|
797
|
800
|
|
798
|
801
|
//文件上传
|
799
|
802
|
func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte) string {
|
|
803
|
+
|
|
804
|
+ //http.Post(strinUrl,"multipart/form-data",bytes.NewReader(file_byte))
|
|
805
|
+
|
800
|
806
|
// 生成签名
|
801
|
807
|
nonce := GetRandomString(32)
|
802
|
808
|
timestamp := time.Now().Unix()
|
|
@@ -808,7 +814,7 @@ func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte)
|
808
|
814
|
inputData := make(map[string]interface{})
|
809
|
815
|
inputMessage["infno"] = "9101" // 交易编码
|
810
|
816
|
inputData["file_name"] = file_name //文件名
|
811
|
|
- inputData["in"] = file_byte //文件数据
|
|
817
|
+ inputData["in"] = bytes.NewReader(file_byte) //文件数据
|
812
|
818
|
inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
|
813
|
819
|
|
814
|
820
|
input["data"] = inputData
|
|
@@ -1159,6 +1165,48 @@ func SetInputMessage(nonce string, timestamp int64, org_name string, doctor stri
|
1159
|
1165
|
return inputMessage
|
1160
|
1166
|
}
|
1161
|
1167
|
|
|
1168
|
+func postFile(filename string, target_url string) (*http.Response, error) {
|
|
1169
|
+ body_buf := bytes.NewBufferString("")
|
|
1170
|
+ body_writer := multipart.NewWriter(body_buf)
|
|
1171
|
+
|
|
1172
|
+ // use the body_writer to write the Part headers to the buffer
|
|
1173
|
+ _, err := body_writer.CreateFormFile("userfile", filename)
|
|
1174
|
+ if err != nil {
|
|
1175
|
+ fmt.Println("error writing to buffer")
|
|
1176
|
+ return nil, err
|
|
1177
|
+ }
|
|
1178
|
+
|
|
1179
|
+ // the file data will be the second part of the body
|
|
1180
|
+ fh, err := os.Open(filename)
|
|
1181
|
+ if err != nil {
|
|
1182
|
+ fmt.Println("error opening file")
|
|
1183
|
+ return nil, err
|
|
1184
|
+ }
|
|
1185
|
+ // need to know the boundary to properly close the part myself.
|
|
1186
|
+ boundary := body_writer.Boundary()
|
|
1187
|
+ //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary)
|
|
1188
|
+ close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary))
|
|
1189
|
+
|
|
1190
|
+ // use multi-reader to defer the reading of the file data until
|
|
1191
|
+ // writing to the socket buffer.
|
|
1192
|
+ request_reader := io.MultiReader(body_buf, fh, close_buf)
|
|
1193
|
+ fi, err := fh.Stat()
|
|
1194
|
+ if err != nil {
|
|
1195
|
+ fmt.Printf("Error Stating file: %s", filename)
|
|
1196
|
+ return nil, err
|
|
1197
|
+ }
|
|
1198
|
+ req, err := http.NewRequest("POST", target_url, request_reader)
|
|
1199
|
+ if err != nil {
|
|
1200
|
+ return nil, err
|
|
1201
|
+ }
|
|
1202
|
+
|
|
1203
|
+ // Set headers for multipart, and Content Length
|
|
1204
|
+ req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundary)
|
|
1205
|
+ req.ContentLength = fi.Size() + int64(body_buf.Len()) + int64(close_buf.Len())
|
|
1206
|
+
|
|
1207
|
+ return http.DefaultClient.Do(req)
|
|
1208
|
+}
|
|
1209
|
+
|
1162
|
1210
|
//func Gdyb1201(psnNo string, org_name string, doctor string) string {
|
1163
|
1211
|
// // 生成签名
|
1164
|
1212
|
// nonce := GetRandomString(32)
|