gdyb_service.go 58KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  1. package service
  2. import (
  3. "XT_New/models"
  4. //"/models"
  5. "bytes"
  6. "crypto/sha256"
  7. "encoding/hex"
  8. "encoding/json"
  9. "fmt"
  10. "io"
  11. "io/ioutil"
  12. "math/rand"
  13. "mime/multipart"
  14. "net/http"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. _ "unsafe"
  21. )
  22. const (
  23. SceretKey = "RhaDw4H0RUbWYyTxmRKM1eSeN0qyGLds" // secretKey 私钥
  24. )
  25. // 人员基本信息
  26. func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  27. // 生成签名
  28. nonce := GetRandomString(32)
  29. timestamp := time.Now().Unix()
  30. signature := setSignature(timestamp, nonce, secret_key)
  31. // 生成输入报文
  32. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  33. input := make(map[string]interface{})
  34. inputData := make(map[string]interface{})
  35. inputMessage["infno"] = "1101" // 交易编码
  36. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  37. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  38. inputData["card_sn"] = "" // 卡识别码
  39. inputData["begntime"] = "" // 开始时间
  40. inputData["psn_cert_type"] = "1" // 人员证件类型
  41. inputData["certno"] = certNo // 证件号码
  42. inputData["psn_name"] = "" // 人员姓名
  43. input["data"] = inputData
  44. inputMessage["input"] = input //交易输入
  45. bytesData, err := json.Marshal(inputMessage)
  46. fmt.Println(string(bytesData))
  47. if err != nil {
  48. fmt.Println(err.Error())
  49. return err.Error()
  50. }
  51. reader := bytes.NewReader(bytesData)
  52. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  53. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  54. request, err := http.NewRequest("POST", url, reader)
  55. if err != nil {
  56. fmt.Println(err.Error())
  57. return err.Error()
  58. }
  59. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  60. request.Header.Set("x-tif-paasid", "sg03_prd")
  61. request.Header.Set("x-tif-signature", signature)
  62. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  63. request.Header.Set("x-tif-nonce", nonce)
  64. client := http.Client{}
  65. resp, err := client.Do(request)
  66. if err != nil {
  67. fmt.Println(err.Error())
  68. return err.Error()
  69. }
  70. respBytes, err := ioutil.ReadAll(resp.Body)
  71. if err != nil {
  72. fmt.Println(err.Error())
  73. return err.Error()
  74. }
  75. fmt.Println(string(respBytes))
  76. str := string(respBytes)
  77. return str
  78. }
  79. // 门诊挂号
  80. func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  81. // 生成签名
  82. nonce := GetRandomString(32)
  83. timestamp := time.Now().Unix()
  84. signature := setSignature(timestamp, nonce, secret_key)
  85. tempTime := time.Unix(timestamp, 0)
  86. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  87. // 生成输入报文
  88. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  89. input := make(map[string]interface{})
  90. inputData := make(map[string]interface{})
  91. inputMessage["infno"] = "2201" // 交易编码
  92. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  93. inputData["insutype"] = insutype // 险种类型(来自1101接口返回)
  94. inputData["begntime"] = timeFormatOne // 开始时间
  95. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  96. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  97. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  98. inputData["atddr_no"] = doctor_id // 医师编码
  99. inputData["dr_name"] = doctor // 医师姓名
  100. inputData["dept_code"] = dept_code // 科室编码
  101. inputData["dept_name"] = dept // 科室名称
  102. inputData["caty"] = "A03.06" // 科别
  103. input["data"] = inputData
  104. inputMessage["input"] = input //交易输入
  105. bytesData, err := json.Marshal(inputMessage)
  106. fmt.Println(string(bytesData))
  107. if err != nil {
  108. fmt.Println(err.Error())
  109. return err.Error()
  110. }
  111. reader := bytes.NewReader(bytesData)
  112. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2201"
  113. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2201"
  114. request, err := http.NewRequest("POST", url, reader)
  115. if err != nil {
  116. fmt.Println(err.Error())
  117. return err.Error()
  118. }
  119. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  120. request.Header.Set("x-tif-paasid", "sg03_prd")
  121. request.Header.Set("x-tif-signature", signature)
  122. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  123. request.Header.Set("x-tif-nonce", nonce)
  124. client := http.Client{}
  125. resp, err := client.Do(request)
  126. if err != nil {
  127. fmt.Println(err.Error())
  128. return err.Error()
  129. }
  130. respBytes, err := ioutil.ReadAll(resp.Body)
  131. if err != nil {
  132. fmt.Println(err.Error())
  133. return err.Error()
  134. }
  135. str := string(respBytes)
  136. fmt.Println(str)
  137. return str
  138. }
  139. func Gdyb2201ForGzyb(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, psn_name string) string {
  140. // 生成签名
  141. nonce := GetRandomString(32)
  142. timestamp := time.Now().Unix()
  143. signature := setSignature(timestamp, nonce, secret_key)
  144. tempTime := time.Unix(timestamp, 0)
  145. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  146. // 生成输入报文
  147. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  148. input := make(map[string]interface{})
  149. inputData := make(map[string]interface{})
  150. inputData2 := make(map[string]interface{})
  151. inputMessage["infno"] = "2201" // 交易编码
  152. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  153. inputData["insutype"] = insutype // 险种类型(来自1101接口返回)
  154. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  155. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  156. inputData["hcard_basinfo"] = "" // 就诊凭证编号
  157. inputData["hcard_chkinfo"] = "" // 就诊凭证编号
  158. inputData["begntime"] = timeFormatOne // 开始时间
  159. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  160. inputData["dept_code"] = dept_code // 科室编码
  161. inputData["dept_name"] = dept // 科室名称
  162. inputData["atddr_no"] = doctor_id // 医师编码
  163. inputData["dr_name"] = doctor // 医师姓名
  164. inputData["caty"] = "A03.06" // 科别
  165. input["mdtrtinfo"] = inputData
  166. inputData2["agnter_name"] = psn_name
  167. inputData2["gnter_rlts"] = "01"
  168. inputData2["agnter_cert_type"] = "01"
  169. inputData2["agnter_certno"] = certNo
  170. inputData2["agnter_tel"] = "13535547901"
  171. inputData2["agnter_addr"] = "xxxxxx"
  172. inputData2["agnter_photo"] = "xxxxxxx"
  173. input["agnterinfo"] = inputData2
  174. inputMessage["input"] = input //交易输入
  175. bytesData, err := json.Marshal(inputMessage)
  176. fmt.Println(string(bytesData))
  177. if err != nil {
  178. fmt.Println(err.Error())
  179. return err.Error()
  180. }
  181. reader := bytes.NewReader(bytesData)
  182. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2201"
  183. request, err := http.NewRequest("POST", url, reader)
  184. if err != nil {
  185. fmt.Println(err.Error())
  186. return err.Error()
  187. }
  188. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  189. request.Header.Set("x-tif-paasid", "sg03_prd")
  190. request.Header.Set("x-tif-signature", signature)
  191. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  192. request.Header.Set("x-tif-nonce", nonce)
  193. client := http.Client{}
  194. resp, err := client.Do(request)
  195. if err != nil {
  196. fmt.Println(err.Error())
  197. return err.Error()
  198. }
  199. respBytes, err := ioutil.ReadAll(resp.Body)
  200. if err != nil {
  201. fmt.Println(err.Error())
  202. return err.Error()
  203. }
  204. str := string(respBytes)
  205. fmt.Println(str)
  206. return str
  207. }
  208. // 门诊挂号撤销
  209. func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  210. // 生成签名
  211. nonce := GetRandomString(32)
  212. timestamp := time.Now().Unix()
  213. signature := setSignature(timestamp, nonce, secret_key)
  214. // 生成输入报文
  215. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", insuplc_admdvs, mdtrtarea_admvs)
  216. input := make(map[string]interface{})
  217. inputData := make(map[string]interface{})
  218. inputMessage["infno"] = "2202" // 交易编码
  219. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  220. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  221. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  222. input["data"] = inputData
  223. inputMessage["input"] = input //交易输入
  224. bytesData, err := json.Marshal(inputMessage)
  225. fmt.Println(string(bytesData))
  226. if err != nil {
  227. fmt.Println(err.Error())
  228. return err.Error()
  229. }
  230. reader := bytes.NewReader(bytesData)
  231. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2202"
  232. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202"
  233. request, err := http.NewRequest("POST", url, reader)
  234. if err != nil {
  235. fmt.Println(err.Error())
  236. return err.Error()
  237. }
  238. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  239. //request.Header.Set("x-tif-paasid", "test_hosp")
  240. request.Header.Set("x-tif-paasid", "sg03_prd")
  241. request.Header.Set("x-tif-signature", signature)
  242. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  243. request.Header.Set("x-tif-nonce", nonce)
  244. client := http.Client{}
  245. resp, err := client.Do(request)
  246. if err != nil {
  247. fmt.Println(err.Error())
  248. return err.Error()
  249. }
  250. respBytes, err := ioutil.ReadAll(resp.Body)
  251. if err != nil {
  252. fmt.Println(err.Error())
  253. return err.Error()
  254. }
  255. str := string(respBytes)
  256. fmt.Println(str)
  257. return str
  258. }
  259. // 门诊就诊信息上传
  260. func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, diag string, org_name string, med_type string, doctor_id int64, fixmedins_code string, diag_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  261. // 生成签名
  262. nonce := GetRandomString(32)
  263. timestamp := time.Now().Unix()
  264. signature := setSignature(timestamp, nonce, secret_key)
  265. tempTime := time.Unix(timestamp, 0)
  266. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  267. // 生成输入报文
  268. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  269. input := make(map[string]interface{})
  270. inputData := make(map[string]interface{})
  271. diseinfo := make([]map[string]interface{}, 0)
  272. inputMessage["infno"] = "2203" // 交易编码
  273. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  274. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  275. inputData["med_type"] = med_type // 医疗类别 16门诊特殊病
  276. inputData["begntime"] = timeFormatOne // 开始时间
  277. inputData["main_cond_dscr"] = "" // 主要病情描述
  278. inputData["dise_codg"] = "" // 病种编码
  279. inputData["dise_name"] = "" // 病种名称
  280. inputData["birctrl_type"] = "" // 计划生育手术类别
  281. inputData["birctrl_matn_date"] = "" // 计划生育手术或生育日期
  282. diseinfo_sun := make(map[string]interface{})
  283. diseinfo_sun["diag_type"] = "1" // 诊断类别
  284. diseinfo_sun["diag_srt_no"] = "1" // 诊断排序号
  285. diseinfo_sun["diag_code"] = diag_code // 诊断代码
  286. diseinfo_sun["diag_name"] = diag // 诊断名称
  287. diseinfo_sun["diag_dept"] = department // 诊断科室
  288. diseinfo_sun["dise_dor_no"] = doctor_id // 诊断医生编码
  289. diseinfo_sun["dise_dor_name"] = doctor // 诊断医生姓名
  290. diseinfo_sun["diag_time"] = timeFormatOne // 诊断时间
  291. diseinfo_sun["vali_flag"] = "1" // 有效标志
  292. diseinfo = append(diseinfo, diseinfo_sun)
  293. input["diseinfo"] = diseinfo
  294. input["mdtrtinfo"] = inputData
  295. inputMessage["input"] = input //交易输入
  296. bytesData, err := json.Marshal(inputMessage)
  297. fmt.Println(string(bytesData))
  298. if err != nil {
  299. fmt.Println(err.Error())
  300. return err.Error()
  301. }
  302. reader := bytes.NewReader(bytesData)
  303. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2203"
  304. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2203"
  305. request, err := http.NewRequest("POST", url, reader)
  306. if err != nil {
  307. fmt.Println(err.Error())
  308. return err.Error()
  309. }
  310. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  311. request.Header.Set("x-tif-paasid", "sg03_prd")
  312. request.Header.Set("x-tif-signature", signature)
  313. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  314. request.Header.Set("x-tif-nonce", nonce)
  315. client := http.Client{}
  316. resp, err := client.Do(request)
  317. if err != nil {
  318. fmt.Println(err.Error())
  319. return err.Error()
  320. }
  321. respBytes, err := ioutil.ReadAll(resp.Body)
  322. if err != nil {
  323. fmt.Println(err.Error())
  324. return err.Error()
  325. }
  326. str := string(respBytes)
  327. fmt.Println(str)
  328. return str
  329. }
  330. type Custom struct {
  331. DetItemFeeSumamt string
  332. Cut string
  333. FeedetlSn string
  334. Price string
  335. MedListCodg string
  336. }
  337. type RequestResult struct {
  338. Output Output `json:"output" form:"output"`
  339. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  340. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  341. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  342. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  343. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  344. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  345. }
  346. type Output struct {
  347. Result Result `json:"result" form:"result"`
  348. }
  349. type Result struct {
  350. BasMednFlag string `json:"bas_medn_flag" form:"bas_medn_flag"`
  351. MedChrgitmType string `json:"med_chrgitm_type" form:"med_chrgitm_type"`
  352. DetItemFeeSumamt int64 `json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  353. HiNegoDrugFlag string `json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  354. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  355. FeedtlSn int64 `json:"feedtl_sn" form:"feedtl_sn"`
  356. UploadDate int64 `json:"upload_date" form:"upload_date"`
  357. AdviceId int64 `json:"advice_id" form:"advice_id"`
  358. Cnt int64 `json:"cnt" form:"cnt"`
  359. Pric float64 `json:"pric" form:"pric"`
  360. PatientId int64 `json:"patient_id" form:"patient_id"`
  361. PricUplmtAmt float64 `json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  362. SelfpayProp float64 `json:"selfpay_prop" form:"selfpay_prop"`
  363. OverlmtAmt float64 `json:"overlmt_amt" form:"overlmt_amt"`
  364. PreselfpayAmt float64 `json:"preselfpay_amt" form:"preselfpay_amt"`
  365. Status int64 `json:"status" form:"status"`
  366. Memo string `json:"memo" form:"memo"`
  367. FeedetlSn string `json:"feedetl_sn" form:"feedetl_sn"`
  368. Mtime int64 `json:"mtime" form:"mtime"`
  369. InscpScpAmt float64 `json:"inscp_scp_amt" form:"inscp_scp_amt"`
  370. DrtReimFlag string `json:"drt_reim_flag" form:"drt_reim_flag"`
  371. Ctime int64 `json:"ctime" form:"ctime"`
  372. ListSpItemFlag string `json:"list_sp_item_flag" form:"list_sp_item_flag"`
  373. ChldMedcFlag string `json:"chld_medc_flag" form:"chld_medc_flag"`
  374. LmtUsedFlag string `json:"lmt_used_flag" form:"lmt_used_flag"`
  375. ChrgitmLv string `json:"chrgitm_lv" form:"chrgitm_lv"`
  376. UserOrgId int64 `json:"user_org_id" form:"user_org_id"`
  377. HisPatientId int64 `json:"his_patient_id" form:"his_patient_id"`
  378. OrderId int64 `json:"order_id" form:"order_id"`
  379. }
  380. // 门诊费用明细信息上传
  381. func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescription, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  382. // 生成签名
  383. nonce := GetRandomString(32)
  384. timestamp := time.Now().Unix()
  385. signature := setSignature(timestamp, nonce, secret_key)
  386. tempTime := time.Unix(timestamp, 0)
  387. //timeFormat := tempTime.Format("20060102150405")
  388. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  389. //chrgBchno := rand.Intn(100000) + 10000
  390. var customs []*Custom
  391. for _, item := range hisPrescription {
  392. if item.Type == 1 { //药品
  393. for _, subItem := range item.HisDoctorAdviceInfo {
  394. if len(subItem.MedListCodg) > 0 {
  395. //var randNum int
  396. //randNum = rand.Intn(10000) + 1000
  397. cus := &Custom{
  398. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  399. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  400. FeedetlSn: subItem.FeedetlSn,
  401. Price: fmt.Sprintf("%.2f", subItem.Price),
  402. MedListCodg: subItem.MedListCodg,
  403. }
  404. customs = append(customs, cus)
  405. }
  406. }
  407. }
  408. if item.Type == 2 { //项目
  409. for _, subItem := range item.HisPrescriptionProject {
  410. //var randNum int
  411. //randNum = rand.Intn(10000) + 1000
  412. if len(subItem.MedListCodg) > 0 {
  413. cut, _ := strconv.ParseFloat(subItem.Count, 64)
  414. cus := &Custom{
  415. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cut),
  416. Cut: fmt.Sprintf("%.2f", cut),
  417. FeedetlSn: subItem.FeedetlSn,
  418. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  419. MedListCodg: subItem.MedListCodg,
  420. }
  421. customs = append(customs, cus)
  422. }
  423. }
  424. }
  425. for _, subItem := range item.HisAdditionalCharge {
  426. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  427. cus := &Custom{
  428. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  429. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  430. FeedetlSn: subItem.FeedetlSn,
  431. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  432. MedListCodg: subItem.XtHisAddtionConfig.Code,
  433. }
  434. customs = append(customs, cus)
  435. }
  436. }
  437. }
  438. // 生成输入报文
  439. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  440. input := make(map[string]interface{})
  441. feedetail := make([]map[string]interface{}, 0)
  442. inputMessage["infno"] = "2204" // 交易编码
  443. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  444. for _, item := range customs {
  445. feedetailInfo := make(map[string]interface{})
  446. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  447. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  448. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  449. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  450. feedetailInfo["dise_codg"] = "" // 病种编码
  451. feedetailInfo["rxno"] = "" // 处方号
  452. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  453. feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间
  454. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  455. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  456. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  457. feedetailInfo["cnt"] = item.Cut // 数量
  458. feedetailInfo["pric"] = item.Price // 单价
  459. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  460. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  461. feedetailInfo["prd_days"] = "0" // 周期天数
  462. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  463. feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码
  464. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  465. feedetailInfo["bilg_dr_codg"] = doctor_id // 开单医生编码
  466. feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名
  467. feedetailInfo["acord_dept_codg"] = "" // 受单科室编码
  468. feedetailInfo["acord_dept_name"] = "" // 受单科室名称
  469. feedetailInfo["orders_dr_code"] = "" // 受单医生编码
  470. feedetailInfo["orders_dr_name"] = "" // 受单医生姓名
  471. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  472. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  473. feedetailInfo["etip_flag"] = "" // 外检标志
  474. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  475. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  476. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  477. feedetail = append(feedetail, feedetailInfo)
  478. }
  479. input["feedetail"] = feedetail
  480. inputMessage["input"] = input //交易输入
  481. bytesData, err := json.Marshal(inputMessage)
  482. fmt.Println("----------")
  483. fmt.Println(string(bytesData))
  484. fmt.Println("----------")
  485. if err != nil {
  486. fmt.Println(err.Error())
  487. return ""
  488. }
  489. reader := bytes.NewReader(bytesData)
  490. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2204"
  491. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204"
  492. request, err := http.NewRequest("POST", url, reader)
  493. if err != nil {
  494. fmt.Println(err.Error())
  495. return ""
  496. }
  497. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  498. request.Header.Set("x-tif-paasid", "sg03_prd")
  499. request.Header.Set("x-tif-signature", signature)
  500. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  501. request.Header.Set("x-tif-nonce", nonce)
  502. client := http.Client{}
  503. resp, err := client.Do(request)
  504. if err != nil {
  505. fmt.Println(err.Error())
  506. return ""
  507. }
  508. respBytes, err := ioutil.ReadAll(resp.Body)
  509. if err != nil {
  510. fmt.Println(err.Error())
  511. return ""
  512. }
  513. return string(respBytes)
  514. //var result RequestResult
  515. //json.Unmarshal(respBytes, &result)
  516. //return &result
  517. }
  518. // 门诊费用明细信息撤销
  519. func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) string {
  520. // 生成签名
  521. nonce := GetRandomString(32)
  522. timestamp := time.Now().Unix()
  523. signature := setSignature(timestamp, nonce, secret_key)
  524. // 生成输入报文
  525. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  526. input := make(map[string]interface{})
  527. inputData := make(map[string]interface{})
  528. inputMessage["infno"] = "2205" // 交易编码
  529. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  530. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  531. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  532. input["data"] = inputData
  533. inputMessage["input"] = input //交易输入
  534. bytesData, err := json.Marshal(inputMessage)
  535. fmt.Println(string(bytesData))
  536. if err != nil {
  537. fmt.Println(err.Error())
  538. return err.Error()
  539. }
  540. reader := bytes.NewReader(bytesData)
  541. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2205"
  542. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  543. request, err := http.NewRequest("POST", url, reader)
  544. fmt.Println(err)
  545. fmt.Println(request)
  546. if err != nil {
  547. fmt.Println(err.Error())
  548. return err.Error()
  549. }
  550. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  551. request.Header.Set("x-tif-paasid", "sg03_prd")
  552. request.Header.Set("x-tif-signature", signature)
  553. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  554. request.Header.Set("x-tif-nonce", nonce)
  555. client := http.Client{}
  556. resp, err := client.Do(request)
  557. if err != nil {
  558. fmt.Println(err.Error())
  559. return err.Error()
  560. }
  561. respBytes, err := ioutil.ReadAll(resp.Body)
  562. if err != nil {
  563. fmt.Println(err.Error())
  564. return err.Error()
  565. }
  566. str := string(respBytes)
  567. fmt.Println(str)
  568. return str
  569. }
  570. // 门诊预结算
  571. func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, secret_key string) string {
  572. // 生成签名
  573. nonce := GetRandomString(32)
  574. timestamp := time.Now().Unix()
  575. signature := setSignature(timestamp, nonce, secret_key)
  576. // 生成输入报文
  577. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", "", "")
  578. input := make(map[string]interface{})
  579. inputData := make(map[string]interface{})
  580. inputMessage["infno"] = "2206" // 交易编码
  581. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  582. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型,
  583. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  584. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  585. inputData["medfee_sumamt"] = total // 医疗费总额
  586. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  587. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  588. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  589. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  590. inputData["insutype"] = insutype // 险种类型
  591. input["data"] = inputData
  592. inputMessage["input"] = input //交易输入
  593. bytesData, err := json.Marshal(inputMessage)
  594. fmt.Println(string(bytesData))
  595. if err != nil {
  596. fmt.Println(err.Error())
  597. return err.Error()
  598. }
  599. reader := bytes.NewReader(bytesData)
  600. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2206"
  601. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206"
  602. request, err := http.NewRequest("POST", url, reader)
  603. if err != nil {
  604. fmt.Println(err.Error())
  605. return err.Error()
  606. }
  607. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  608. request.Header.Set("x-tif-paasid", "sg03_prd")
  609. request.Header.Set("x-tif-signature", signature)
  610. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  611. request.Header.Set("x-tif-nonce", nonce)
  612. client := http.Client{}
  613. resp, err := client.Do(request)
  614. if err != nil {
  615. fmt.Println(err.Error())
  616. return err.Error()
  617. }
  618. respBytes, err := ioutil.ReadAll(resp.Body)
  619. if err != nil {
  620. fmt.Println(err.Error())
  621. return err.Error()
  622. }
  623. str := string(respBytes)
  624. fmt.Println(str)
  625. return str
  626. }
  627. // 门诊结算
  628. func Gdyb2207(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  629. // 生成签名
  630. nonce := GetRandomString(32)
  631. timestamp := time.Now().Unix()
  632. signature := setSignature(timestamp, nonce, secret_key)
  633. // 生成输入报文
  634. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  635. input := make(map[string]interface{})
  636. inputData := make(map[string]interface{})
  637. inputMessage["infno"] = "2207" // 交易编码
  638. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  639. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  640. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  641. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  642. inputData["medfee_sumamt"] = total // 医疗费总额
  643. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  644. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  645. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  646. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  647. inputData["insutype"] = insutype // 险种类型
  648. inputData["invono"] = "" // 发票号
  649. input["data"] = inputData
  650. inputMessage["input"] = input //交易输入
  651. bytesData, err := json.Marshal(inputMessage)
  652. fmt.Println(string(bytesData))
  653. if err != nil {
  654. fmt.Println(err.Error())
  655. return err.Error()
  656. }
  657. reader := bytes.NewReader(bytesData)
  658. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207"
  659. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  660. request, err := http.NewRequest("POST", url, reader)
  661. if err != nil {
  662. fmt.Println(err.Error())
  663. return err.Error()
  664. }
  665. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  666. request.Header.Set("x-tif-paasid", "sg03_prd")
  667. request.Header.Set("x-tif-signature", signature)
  668. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  669. request.Header.Set("x-tif-nonce", nonce)
  670. client := http.Client{}
  671. resp, err := client.Do(request)
  672. if err != nil {
  673. fmt.Println(err.Error())
  674. return err.Error()
  675. }
  676. respBytes, err := ioutil.ReadAll(resp.Body)
  677. if err != nil {
  678. fmt.Println(err.Error())
  679. return err.Error()
  680. }
  681. str := string(respBytes)
  682. fmt.Println(str)
  683. return str
  684. }
  685. // 门诊结算撤销
  686. func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string {
  687. // 生成签名
  688. nonce := GetRandomString(32)
  689. timestamp := time.Now().Unix()
  690. signature := setSignature(timestamp, nonce, secret_key)
  691. // 生成输入报文
  692. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  693. input := make(map[string]interface{})
  694. inputData := make(map[string]interface{})
  695. inputMessage["infno"] = "2208" // 交易编码
  696. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  697. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  698. inputData["setl_id"] = setlId // 结算 ID
  699. input["data"] = inputData
  700. inputMessage["input"] = input //交易输入
  701. bytesData, err := json.Marshal(inputMessage)
  702. fmt.Println(string(bytesData))
  703. if err != nil {
  704. fmt.Println(err.Error())
  705. return err.Error()
  706. }
  707. reader := bytes.NewReader(bytesData)
  708. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2208"
  709. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  710. request, err := http.NewRequest("POST", url, reader)
  711. if err != nil {
  712. fmt.Println(err.Error())
  713. return err.Error()
  714. }
  715. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  716. request.Header.Set("x-tif-paasid", "sg03_prd")
  717. request.Header.Set("x-tif-signature", signature)
  718. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  719. request.Header.Set("x-tif-nonce", nonce)
  720. client := http.Client{}
  721. resp, err := client.Do(request)
  722. if err != nil {
  723. fmt.Println(err.Error())
  724. return err.Error()
  725. }
  726. respBytes, err := ioutil.ReadAll(resp.Body)
  727. if err != nil {
  728. fmt.Println(err.Error())
  729. return err.Error()
  730. }
  731. str := string(respBytes)
  732. fmt.Println(str)
  733. return str
  734. }
  735. // 医药机构费用结算对总账 func Gdyb3201( org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string {
  736. func Gdyb3201(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  737. fmt.Println("11222333-----")
  738. fmt.Println(baseParams)
  739. fmt.Println(businessParams)
  740. // 生成签名
  741. nonce := GetRandomString(32)
  742. timestamp := time.Now().Unix()
  743. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  744. // 生成输入报文
  745. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  746. input := make(map[string]interface{})
  747. inputData := make(map[string]interface{})
  748. inputMessage["infno"] = "3201" // 交易编码
  749. inputData["insutype"] = businessParams.Insutype // 险种
  750. inputData["clr_type"] = businessParams.ClrType // 就诊 ID(来自2201接口返回)
  751. inputData["setl_optins"] = baseParams.OrgName // 结算经办机构
  752. inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间
  753. inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间
  754. inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额
  755. inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额
  756. inputData["acct_pay"] = businessParams.AcctPay //个人账户支付金额
  757. inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
  758. input["data"] = inputData
  759. inputMessage["input"] = input //交易输入
  760. bytesData, err := json.Marshal(inputMessage)
  761. fmt.Println(string(bytesData))
  762. if err != nil {
  763. fmt.Println(err.Error())
  764. return err.Error()
  765. }
  766. reader := bytes.NewReader(bytesData)
  767. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3201"
  768. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3201"
  769. request, err := http.NewRequest("POST", url, reader)
  770. if err != nil {
  771. fmt.Println(err.Error())
  772. return err.Error()
  773. }
  774. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  775. request.Header.Set("x-tif-paasid", "sg03_prd")
  776. request.Header.Set("x-tif-signature", signature)
  777. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  778. request.Header.Set("x-tif-nonce", nonce)
  779. client := http.Client{}
  780. resp, err := client.Do(request)
  781. if err != nil {
  782. fmt.Println(err.Error())
  783. return err.Error()
  784. }
  785. respBytes, err := ioutil.ReadAll(resp.Body)
  786. if err != nil {
  787. fmt.Println(err.Error())
  788. return err.Error()
  789. }
  790. str := string(respBytes)
  791. fmt.Println(str)
  792. return str
  793. }
  794. type Params struct {
  795. FileName string `json:"file_name"` //产品ID
  796. In []byte `json:"in"` //
  797. FixmedinsCode string `json:"fixmedins_code"` //调用环境生产为1 沙盒2
  798. }
  799. //文件上传
  800. //文件上传
  801. func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte) string {
  802. // 生成签名
  803. nonce := GetRandomString(32)
  804. timestamp := time.Now().Unix()
  805. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  806. buf := new(bytes.Buffer)
  807. buf.ReadFrom(strings.NewReader(string(file_byte)))
  808. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  809. input := make(map[string]interface{})
  810. inputData := make(map[string]interface{})
  811. inputMessage["infno"] = "9101" // 交易编码
  812. inputData["file_name"] = file_name //文件名
  813. inputData["in"] = bytes.NewBuffer(file_byte).Bytes() //文件数据
  814. inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
  815. input["fsUploadIn"] = inputData
  816. inputMessage["input"] = input //交易输入
  817. bytesData, err := json.Marshal(inputMessage)
  818. fmt.Println(string(bytesData))
  819. if err != nil {
  820. fmt.Println(err.Error())
  821. return err.Error()
  822. }
  823. reader := bytes.NewReader(bytesData)
  824. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9101"
  825. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9101"
  826. request, err := http.NewRequest("POST", url, reader)
  827. if err != nil {
  828. fmt.Println(err.Error())
  829. return err.Error()
  830. }
  831. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  832. request.Header.Set("x-tif-paasid", "sg03_prd")
  833. request.Header.Set("x-tif-signature", signature)
  834. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  835. request.Header.Set("x-tif-nonce", nonce)
  836. client := http.Client{}
  837. resp, err := client.Do(request)
  838. if err != nil {
  839. fmt.Println(err.Error())
  840. return err.Error()
  841. }
  842. respBytes, err := ioutil.ReadAll(resp.Body)
  843. if err != nil {
  844. fmt.Println(err.Error())
  845. return err.Error()
  846. }
  847. str := string(respBytes)
  848. fmt.Println(str)
  849. return str
  850. }
  851. func Gdyb9102(baseParams models.BaseParams, file_name string, file_qury_no string) string {
  852. // 生成签名
  853. nonce := GetRandomString(32)
  854. timestamp := time.Now().Unix()
  855. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  856. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  857. input := make(map[string]interface{})
  858. inputData := make(map[string]interface{})
  859. inputMessage["infno"] = "9102" // 交易编码
  860. inputData["file_name"] = file_name //文件名
  861. inputData["file_qury_no"] = "fsi/H44022900158/" + file_qury_no //文件数据
  862. inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
  863. input["fsDownloadIn"] = inputData
  864. inputMessage["input"] = input //交易输入
  865. bytesData, err := json.Marshal(inputMessage)
  866. fmt.Println(string(bytesData))
  867. if err != nil {
  868. fmt.Println(err.Error())
  869. return err.Error()
  870. }
  871. reader := bytes.NewReader(bytesData)
  872. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9102"
  873. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9102"
  874. request, err := http.NewRequest("POST", url, reader)
  875. if err != nil {
  876. fmt.Println(err.Error())
  877. return err.Error()
  878. }
  879. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  880. request.Header.Set("x-tif-paasid", "sg03_prd")
  881. request.Header.Set("x-tif-signature", signature)
  882. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  883. request.Header.Set("x-tif-nonce", nonce)
  884. client := http.Client{}
  885. resp, err := client.Do(request)
  886. if err != nil {
  887. fmt.Println(err.Error())
  888. return err.Error()
  889. }
  890. respBytes, err := ioutil.ReadAll(resp.Body)
  891. if err != nil {
  892. fmt.Println(err.Error())
  893. return err.Error()
  894. }
  895. str := string(respBytes)
  896. fmt.Println(str)
  897. return str
  898. }
  899. func Gdyb3202(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  900. // 生成签名
  901. nonce := GetRandomString(32)
  902. timestamp := time.Now().Unix()
  903. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  904. // 生成输入报文
  905. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  906. input := make(map[string]interface{})
  907. inputData := make(map[string]interface{})
  908. inputMessage["infno"] = "3202" // 交易编码
  909. inputData["file_qury_no"] = "fsi/H44022900158/" + businessParams.FileQuryNo // 险种
  910. inputData["setl_optins"] = baseParams.OrgName // 结算经办机构
  911. inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间
  912. inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间
  913. inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额
  914. inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额
  915. inputData["cash_payamt"] = businessParams.CashPayamt //现金支付金额
  916. inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
  917. input["data"] = inputData
  918. inputMessage["input"] = input //交易输入
  919. bytesData, err := json.Marshal(inputMessage)
  920. fmt.Println(string(bytesData))
  921. if err != nil {
  922. fmt.Println(err.Error())
  923. return err.Error()
  924. }
  925. reader := bytes.NewReader(bytesData)
  926. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3202"
  927. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3202"
  928. request, err := http.NewRequest("POST", url, reader)
  929. if err != nil {
  930. fmt.Println(err.Error())
  931. return err.Error()
  932. }
  933. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  934. request.Header.Set("x-tif-paasid", "sg03_prd")
  935. request.Header.Set("x-tif-signature", signature)
  936. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  937. request.Header.Set("x-tif-nonce", nonce)
  938. client := http.Client{}
  939. resp, err := client.Do(request)
  940. if err != nil {
  941. fmt.Println(err.Error())
  942. return err.Error()
  943. }
  944. respBytes, err := ioutil.ReadAll(resp.Body)
  945. if err != nil {
  946. fmt.Println(err.Error())
  947. return err.Error()
  948. }
  949. str := string(respBytes)
  950. fmt.Println(str)
  951. return str
  952. }
  953. func Gdyb5203(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  954. // 生成签名
  955. nonce := GetRandomString(32)
  956. timestamp := time.Now().Unix()
  957. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  958. // 生成输入报文
  959. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  960. input := make(map[string]interface{})
  961. inputData := make(map[string]interface{})
  962. inputMessage["infno"] = "5203" // 交易编码
  963. inputData["psn_no"] = businessParams.PsnNo
  964. inputData["setl_id"] = businessParams.SetlId
  965. inputData["mdtrt_id"] = businessParams.MdtrtId
  966. input["data"] = inputData
  967. inputMessage["input"] = input //交易输入
  968. bytesData, err := json.Marshal(inputMessage)
  969. fmt.Println(string(bytesData))
  970. if err != nil {
  971. fmt.Println(err.Error())
  972. return err.Error()
  973. }
  974. reader := bytes.NewReader(bytesData)
  975. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/5203"
  976. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/5203"
  977. request, err := http.NewRequest("POST", url, reader)
  978. if err != nil {
  979. fmt.Println(err.Error())
  980. return err.Error()
  981. }
  982. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  983. request.Header.Set("x-tif-paasid", "sg03_prd")
  984. request.Header.Set("x-tif-signature", signature)
  985. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  986. request.Header.Set("x-tif-nonce", nonce)
  987. client := http.Client{}
  988. resp, err := client.Do(request)
  989. if err != nil {
  990. fmt.Println(err.Error())
  991. return err.Error()
  992. }
  993. respBytes, err := ioutil.ReadAll(resp.Body)
  994. if err != nil {
  995. fmt.Println(err.Error())
  996. return err.Error()
  997. }
  998. str := string(respBytes)
  999. fmt.Println(str)
  1000. return str
  1001. }
  1002. // 门诊结算撤销
  1003. //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
  1004. // // 生成签名
  1005. // nonce := GetRandomString(32)
  1006. // timestamp := time.Now().Unix()
  1007. // signature := setSignature(timestamp, nonce)
  1008. //
  1009. // // 生成输入报文
  1010. // inputMessage := SetInputMessage(nonce, timestamp)
  1011. // input := make(map[string]interface{})
  1012. // inputData := make(map[string]interface{})
  1013. // inputMessage["infno"] = "4101" // 交易编码
  1014. //
  1015. // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回)
  1016. // inputData["setl_id"] = setlId // 结算 ID 必填
  1017. // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填
  1018. // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填
  1019. // inputData["hi_setl_lv"] = "" // 医保结算等级
  1020. // inputData["hi_no"] = "" // 医保编号
  1021. // inputData["medcasno"] = "" // 病案号 必填
  1022. // inputData["dcla_time"] = "" // 申报时间 必填
  1023. // inputData["psn_name"] = "" // 人员姓名 必填
  1024. // inputData["gend"] = "" // 性别 必填
  1025. // inputData["brdy"] = "" // 出生日期 必填
  1026. // inputData["age"] = "" // 年龄 必填
  1027. // inputData["ntly"] = "" // 国籍 必填
  1028. // inputData["nwb_age"] = "" // 年龄 必填
  1029. // inputData["naty"] = "" // 民族 必填
  1030. // inputData["patn_cert_type"] = "" // 患者证件类别 必填
  1031. // inputData["certno"] = "" // 证件号码 必填
  1032. // inputData["prfs"] = "" // 职业 必填
  1033. // inputData["curr_addr"] = "" // 现住址 必填
  1034. // inputData["emp_name"] = "" // 单位名称 必填
  1035. // inputData["emp_addr"] = "" // 单位地址 必填
  1036. // inputData["emp_tel"] = "" // 单位电话 必填
  1037. // inputData["poscode"] = "" // 邮编 必填
  1038. // inputData["coner_name"] = "" // 联系人姓名 必填
  1039. // inputData["patn_rlts"] = "" // 与患者关系 必填
  1040. // inputData["coner_addr"] = "" // 联系人地址 必填
  1041. // inputData["coner_tel"] = "" // 联系人电话 必填
  1042. // inputData["hi_type"] = "" // 医保类型 必填
  1043. // inputData["insuplc"] = "" // 参保地 必填
  1044. // inputData["sp_psn_type"] = "" // 特殊人员类型 必填
  1045. // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填
  1046. // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填
  1047. // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填
  1048. // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填
  1049. // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填
  1050. // inputData["ipt_med_type"] = "" // 住院医疗类型 必填
  1051. // inputData["adm_way"] = "" // 入院途径 必填
  1052. // inputData["trt_type"] = "" // 治疗类别 必填
  1053. // inputData["adm_time"] = "" // 入院时间 必填
  1054. // inputData["adm_caty"] = "" // 入院科别 必填
  1055. // inputData["refldept_dept"] = "" // 转科科别 必填
  1056. // inputData["dscg_time"] = "" // 出院时间 必填
  1057. // inputData["dscg_caty"] = "" // 出院科别 必填
  1058. // inputData["act_ipt_days"] = "" // 实际住院天数 必填
  1059. // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填
  1060. // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填
  1061. // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填
  1062. // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填
  1063. // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填
  1064. // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填
  1065. // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填
  1066. // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填
  1067. // inputData["bld_cat"] = "" // 输血品种 必填
  1068. // inputData["bld_amt"] = "" // 输血量 必填
  1069. // inputData["bld_unt"] = "" // 输血计量单位 必填
  1070. // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填
  1071. // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填
  1072. // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填
  1073. // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填
  1074. // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填
  1075. // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填
  1076. // inputData["bill_code"] = "" // 票据代码 必填
  1077. // inputData["bill_no"] = "" // 票据号码 必填
  1078. // inputData["biz_sn"] = "" // 业务流水号 必填
  1079. // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填
  1080. // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填
  1081. // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填
  1082. // inputData["chfpdr_code"] = "" // 主诊医师代码 必填
  1083. // inputData["setl_begn_date"] = "" // 结算开始日期 必填
  1084. // inputData["setl_end_date"] = "" // 结算结束日期 必填
  1085. // inputData["psn_selfpay"] = "" // 个人自付 必填
  1086. // inputData["psn_ownpay"] = "" // 个人自费 必填
  1087. // inputData["acct_pay"] = "" // 个人账户支出 必填
  1088. // inputData["hi_paymtd"] = "" // 医保支付方式 必填
  1089. // inputData["hsorg"] = "" // 医保机构 必填
  1090. // inputData["hsorg_opter"] = "" // 医保机构经办人 必填
  1091. // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填
  1092. // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填
  1093. //
  1094. // payinfo := make([]map[string]interface{},0) // 基金支付信息
  1095. // payinfotemp := make(map[string]interface{})
  1096. // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填
  1097. // payinfotemp["fund_payamt"] = "" // 基金支付金额
  1098. // payinfo = append(payinfo,payinfotemp)
  1099. //
  1100. // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
  1101. // opspdiseinfotemp := make(map[string]interface{})
  1102. // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填
  1103. // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填
  1104. // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  1105. // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  1106. // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
  1107. //
  1108. // diseinfo := make([]map[string]interface{},0) // 住院诊断信息
  1109. // diseinfotemp := make(map[string]interface{})
  1110. // diseinfotemp["diag_type"] = "" // 诊断类别 必填
  1111. // diseinfotemp["diag_code"] = "" // 诊断代码 必填
  1112. // diseinfotemp["diag_name"] = "" // 诊断名称 必填
  1113. // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填
  1114. // diseinfo = append(diseinfo,diseinfotemp)
  1115. //
  1116. // iteminfo := make([]map[string]interface{},0) // 住院诊断信息
  1117. // iteminfotemp := make(map[string]interface{})
  1118. // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填
  1119. // iteminfotemp["amt"] = "" // 金额 必填
  1120. // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填
  1121. // iteminfotemp["clab_amt"] = "" // 乙类金额 必填
  1122. // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填
  1123. // iteminfotemp["oth_amt"] = "" // 其他金额 必填
  1124. // iteminfo = append(iteminfo,iteminfotemp)
  1125. //
  1126. // oprninfo := make([]map[string]interface{},0) // 手术操作信息
  1127. // oprninfotemp := make(map[string]interface{})
  1128. // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填
  1129. // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  1130. // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  1131. // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填
  1132. // oprninfotemp["anst_way"] = "" // 麻醉方式 必填
  1133. // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填
  1134. // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填
  1135. // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填
  1136. // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填
  1137. // oprninfo = append(oprninfo,iteminfotemp)
  1138. //
  1139. // icuinfo := make([]map[string]interface{},0) // 重症监护信息
  1140. // icuinfotemp := make(map[string]interface{})
  1141. // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填
  1142. // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填
  1143. // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填
  1144. // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填
  1145. // icuinfo = append(icuinfo,iteminfotemp)
  1146. //
  1147. //
  1148. //
  1149. //
  1150. // input["setlinfo"] = inputData
  1151. // input["payinfo"] = payinfo
  1152. // input["opspdiseinfo"] = opspdiseinfo
  1153. // input["diseinfo"] = diseinfo
  1154. // input["iteminfo"] = iteminfo
  1155. // input["oprninfo"] = oprninfo
  1156. // input["icuinfo"] = icuinfo
  1157. // inputMessage["input"] = input //交易输入
  1158. //
  1159. // bytesData, err := json.Marshal(inputMessage)
  1160. // fmt.Println(string(bytesData))
  1161. // if err != nil {
  1162. // fmt.Println(err.Error())
  1163. // return err.Error()
  1164. // }
  1165. // reader := bytes.NewReader(bytesData)
  1166. //
  1167. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  1168. // request, err := http.NewRequest("POST", url, reader)
  1169. // if err != nil {
  1170. // fmt.Println(err.Error())
  1171. // return err.Error()
  1172. // }
  1173. //
  1174. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1175. // request.Header.Set("x-tif-paasid", "test_hosp")
  1176. // request.Header.Set("x-tif-signature", signature)
  1177. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1178. // request.Header.Set("x-tif-nonce", nonce)
  1179. //
  1180. // client := http.Client{}
  1181. // resp, err := client.Do(request)
  1182. // if err != nil {
  1183. // fmt.Println(err.Error())
  1184. // return err.Error()
  1185. // }
  1186. // respBytes, err := ioutil.ReadAll(resp.Body)
  1187. // if err != nil {
  1188. // fmt.Println(err.Error())
  1189. // return err.Error()
  1190. // }
  1191. // str := string(respBytes)
  1192. // fmt.Println(str)
  1193. // return str
  1194. //}
  1195. // 生成签名
  1196. func setSignature(timestamp int64, nonce string, secret_key string) string {
  1197. str := strconv.FormatInt(timestamp, 10) + secret_key + nonce + strconv.FormatInt(timestamp, 10)
  1198. hash := sha256.New()
  1199. //输入数据
  1200. hash.Write([]byte(str))
  1201. //计算哈希值
  1202. bytes := hash.Sum(nil)
  1203. //将字符串编码为16进制格式,返回字符串
  1204. hashCode := hex.EncodeToString(bytes)
  1205. //返回哈希值
  1206. return hashCode
  1207. }
  1208. // 生成随机字符串
  1209. func GetRandomString(l int) string {
  1210. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1211. bytes := []byte(str)
  1212. result := []byte{}
  1213. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  1214. for i := 0; i < l; i++ {
  1215. result = append(result, bytes[r.Intn(len(bytes))])
  1216. }
  1217. return string(result)
  1218. }
  1219. // 生成基础报文
  1220. func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) map[string]interface{} {
  1221. // 生成签名
  1222. tempTime := time.Unix(timestamp, 0)
  1223. timeFormat := tempTime.Format("20060102150405")
  1224. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1225. randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  1226. // 生成输入报文
  1227. inputMessage := make(map[string]interface{})
  1228. inputMessage["infno"] = "1101" // 交易编码
  1229. inputMessage["msgid"] = fixmedins_code + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID
  1230. inputMessage["mdtrtarea_admvs"] = mdtrtarea_admvs // 就医地医保区划
  1231. inputMessage["insuplc_admdvs"] = insuplc_admdvs // 参保地医保区划
  1232. inputMessage["recer_sys_code"] = "01" // 接收方系统代码
  1233. inputMessage["dev_no"] = "" // 设备编号
  1234. inputMessage["dev_safe_info"] = "" // 设备安全信息
  1235. inputMessage["cainfo"] = "" // 数字签名信息
  1236. inputMessage["signtype"] = "" // 签名类型
  1237. inputMessage["infver"] = "V1.1" // 接收方系统代码
  1238. inputMessage["opter_type"] = "1" // 经办人类别
  1239. inputMessage["opter"] = doctor // 经办人
  1240. inputMessage["opter_name"] = doctor // 经办人姓名
  1241. inputMessage["inf_time"] = timeFormatOne // 交易时间
  1242. inputMessage["fixmedins_code"] = fixmedins_code // 定点医药机构编号
  1243. inputMessage["fixmedins_name"] = org_name //定点医药机构名称
  1244. inputMessage["sign_no"] = "" //交易签到流水号
  1245. return inputMessage
  1246. }
  1247. func postFile(filename string, target_url string) (*http.Response, error) {
  1248. body_buf := bytes.NewBufferString("")
  1249. body_writer := multipart.NewWriter(body_buf)
  1250. // use the body_writer to write the Part headers to the buffer
  1251. _, err := body_writer.CreateFormFile("userfile", filename)
  1252. if err != nil {
  1253. fmt.Println("error writing to buffer")
  1254. return nil, err
  1255. }
  1256. // the file data will be the second part of the body
  1257. fh, err := os.Open(filename)
  1258. if err != nil {
  1259. fmt.Println("error opening file")
  1260. return nil, err
  1261. }
  1262. // need to know the boundary to properly close the part myself.
  1263. boundary := body_writer.Boundary()
  1264. //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary)
  1265. close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary))
  1266. // use multi-reader to defer the reading of the file data until
  1267. // writing to the socket buffer.
  1268. request_reader := io.MultiReader(body_buf, fh, close_buf)
  1269. fi, err := fh.Stat()
  1270. if err != nil {
  1271. fmt.Printf("Error Stating file: %s", filename)
  1272. return nil, err
  1273. }
  1274. req, err := http.NewRequest("POST", target_url, request_reader)
  1275. if err != nil {
  1276. return nil, err
  1277. }
  1278. // Set headers for multipart, and Content Length
  1279. req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundary)
  1280. req.ContentLength = fi.Size() + int64(body_buf.Len()) + int64(close_buf.Len())
  1281. return http.DefaultClient.Do(req)
  1282. }
  1283. //func Gdyb1201(psnNo string, org_name string, doctor string) string {
  1284. // // 生成签名
  1285. // nonce := GetRandomString(32)
  1286. // timestamp := time.Now().Unix()
  1287. // signature := setSignature(timestamp, nonce)
  1288. //
  1289. // // 生成输入报文
  1290. // inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  1291. // input := make(map[string]interface{})
  1292. // inputData := make(map[string]interface{})
  1293. // inputMessage["infno"] = "1201" // 交易编码
  1294. // inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回)
  1295. // inputData["fixmedins_name"] = org_name // 人员编号 (来自1101接口返回)
  1296. // inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回)
  1297. //
  1298. // input["medinsinfo"] = inputData
  1299. // inputMessage["input"] = input //交易输入
  1300. //
  1301. // bytesData, err := json.Marshal(inputMessage)
  1302. // fmt.Println(string(bytesData))
  1303. // if err != nil {
  1304. // fmt.Println(err.Error())
  1305. // return err.Error()
  1306. // }
  1307. // reader := bytes.NewReader(bytesData)
  1308. //
  1309. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201"
  1310. // request, err := http.NewRequest("POST", url, reader)
  1311. // if err != nil {
  1312. // fmt.Println(err.Error())
  1313. // return err.Error()
  1314. // }
  1315. //
  1316. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1317. // request.Header.Set("x-tif-paasid", "test_hosp")
  1318. // request.Header.Set("x-tif-signature", signature)
  1319. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1320. // request.Header.Set("x-tif-nonce", nonce)
  1321. //
  1322. // client := http.Client{}
  1323. // resp, err := client.Do(request)
  1324. // if err != nil {
  1325. // fmt.Println(err.Error())
  1326. // return err.Error()
  1327. // }
  1328. // respBytes, err := ioutil.ReadAll(resp.Body)
  1329. // if err != nil {
  1330. // fmt.Println(err.Error())
  1331. // return err.Error()
  1332. // }
  1333. // str := string(respBytes)
  1334. // fmt.Println(str)
  1335. // return str
  1336. //}
  1337. func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
  1338. file, err := os.Open(path)
  1339. if err != nil {
  1340. return nil, err
  1341. }
  1342. defer file.Close()
  1343. body := &bytes.Buffer{}
  1344. writer := multipart.NewWriter(body)
  1345. part, err := writer.CreateFormFile(paramName, filepath.Base(path))
  1346. if err != nil {
  1347. return nil, err
  1348. }
  1349. _, err = io.Copy(part, file)
  1350. for key, val := range params {
  1351. _ = writer.WriteField(key, val)
  1352. }
  1353. err = writer.Close()
  1354. if err != nil {
  1355. return nil, err
  1356. }
  1357. req, err := http.NewRequest("POST", uri, body)
  1358. req.Header.Set("Content-Type", writer.FormDataContentType())
  1359. return req, err
  1360. }