gdyb_service.go 39KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. package service
  2. import (
  3. "XT_New/models"
  4. "bytes"
  5. "crypto/sha256"
  6. "encoding/hex"
  7. "encoding/json"
  8. "fmt"
  9. "io/ioutil"
  10. "math/rand"
  11. "net/http"
  12. "strconv"
  13. "time"
  14. _ "unsafe"
  15. )
  16. const (
  17. SceretKey = "RhaDw4H0RUbWYyTxmRKM1eSeN0qyGLds" // secretKey 私钥
  18. )
  19. // 人员基本信息
  20. func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string) string {
  21. // 生成签名
  22. nonce := GetRandomString(32)
  23. timestamp := time.Now().Unix()
  24. signature := setSignature(timestamp, nonce)
  25. // 生成输入报文
  26. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code)
  27. input := make(map[string]interface{})
  28. inputData := make(map[string]interface{})
  29. inputMessage["infno"] = "1101" // 交易编码
  30. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  31. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  32. inputData["card_sn"] = "" // 卡识别码
  33. inputData["begntime"] = "" // 开始时间
  34. inputData["psn_cert_type"] = "" // 人员证件类型
  35. inputData["certno"] = "" // 证件号码
  36. inputData["psn_name"] = "" // 人员姓名
  37. input["data"] = inputData
  38. inputMessage["input"] = input //交易输入
  39. bytesData, err := json.Marshal(inputMessage)
  40. fmt.Println(string(bytesData))
  41. if err != nil {
  42. fmt.Println(err.Error())
  43. return err.Error()
  44. }
  45. reader := bytes.NewReader(bytesData)
  46. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  47. request, err := http.NewRequest("POST", url, reader)
  48. if err != nil {
  49. fmt.Println(err.Error())
  50. return err.Error()
  51. }
  52. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  53. request.Header.Set("x-tif-paasid", "test_hosp")
  54. request.Header.Set("x-tif-signature", signature)
  55. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  56. request.Header.Set("x-tif-nonce", nonce)
  57. client := http.Client{}
  58. resp, err := client.Do(request)
  59. if err != nil {
  60. fmt.Println(err.Error())
  61. return err.Error()
  62. }
  63. respBytes, err := ioutil.ReadAll(resp.Body)
  64. if err != nil {
  65. fmt.Println(err.Error())
  66. return err.Error()
  67. }
  68. fmt.Println(string(respBytes))
  69. str := string(respBytes)
  70. return str
  71. }
  72. // 门诊挂号
  73. func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string) string {
  74. // 生成签名
  75. nonce := GetRandomString(32)
  76. timestamp := time.Now().Unix()
  77. signature := setSignature(timestamp, nonce)
  78. tempTime := time.Unix(timestamp, 0)
  79. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  80. // 生成输入报文
  81. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code)
  82. input := make(map[string]interface{})
  83. inputData := make(map[string]interface{})
  84. inputMessage["infno"] = "2201" // 交易编码
  85. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  86. inputData["insutype"] = insutype // 险种类型(来自1101接口返回)
  87. inputData["begntime"] = timeFormatOne // 开始时间
  88. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  89. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  90. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  91. inputData["atddr_no"] = "1002" // 医师编码
  92. inputData["dr_name"] = doctor // 医师姓名
  93. inputData["dept_code"] = "3002" // 科室编码
  94. inputData["dept_name"] = dept // 科室名称
  95. inputData["caty"] = "A03.06" // 科别
  96. input["data"] = inputData
  97. inputMessage["input"] = input //交易输入
  98. bytesData, err := json.Marshal(inputMessage)
  99. fmt.Println(string(bytesData))
  100. if err != nil {
  101. fmt.Println(err.Error())
  102. return err.Error()
  103. }
  104. reader := bytes.NewReader(bytesData)
  105. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2201"
  106. request, err := http.NewRequest("POST", url, reader)
  107. if err != nil {
  108. fmt.Println(err.Error())
  109. return err.Error()
  110. }
  111. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  112. request.Header.Set("x-tif-paasid", "test_hosp")
  113. request.Header.Set("x-tif-signature", signature)
  114. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  115. request.Header.Set("x-tif-nonce", nonce)
  116. client := http.Client{}
  117. resp, err := client.Do(request)
  118. if err != nil {
  119. fmt.Println(err.Error())
  120. return err.Error()
  121. }
  122. respBytes, err := ioutil.ReadAll(resp.Body)
  123. if err != nil {
  124. fmt.Println(err.Error())
  125. return err.Error()
  126. }
  127. str := string(respBytes)
  128. fmt.Println(str)
  129. return str
  130. }
  131. // 门诊挂号撤销
  132. func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string, doctor string) string {
  133. // 生成签名
  134. nonce := GetRandomString(32)
  135. timestamp := time.Now().Unix()
  136. signature := setSignature(timestamp, nonce)
  137. // 生成输入报文
  138. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  139. input := make(map[string]interface{})
  140. inputData := make(map[string]interface{})
  141. inputMessage["infno"] = "2202" // 交易编码
  142. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  143. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  144. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  145. input["data"] = inputData
  146. inputMessage["input"] = input //交易输入
  147. bytesData, err := json.Marshal(inputMessage)
  148. fmt.Println(string(bytesData))
  149. if err != nil {
  150. fmt.Println(err.Error())
  151. return err.Error()
  152. }
  153. reader := bytes.NewReader(bytesData)
  154. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202"
  155. request, err := http.NewRequest("POST", url, reader)
  156. if err != nil {
  157. fmt.Println(err.Error())
  158. return err.Error()
  159. }
  160. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  161. request.Header.Set("x-tif-paasid", "test_hosp")
  162. request.Header.Set("x-tif-signature", signature)
  163. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  164. request.Header.Set("x-tif-nonce", nonce)
  165. client := http.Client{}
  166. resp, err := client.Do(request)
  167. if err != nil {
  168. fmt.Println(err.Error())
  169. return err.Error()
  170. }
  171. respBytes, err := ioutil.ReadAll(resp.Body)
  172. if err != nil {
  173. fmt.Println(err.Error())
  174. return err.Error()
  175. }
  176. str := string(respBytes)
  177. fmt.Println(str)
  178. return str
  179. }
  180. // 门诊就诊信息上传
  181. func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, diag string, org_name string, med_type string, doctor_id int64, fixmedins_code string) string {
  182. // 生成签名
  183. nonce := GetRandomString(32)
  184. timestamp := time.Now().Unix()
  185. signature := setSignature(timestamp, nonce)
  186. tempTime := time.Unix(timestamp, 0)
  187. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  188. // 生成输入报文
  189. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code)
  190. input := make(map[string]interface{})
  191. inputData := make(map[string]interface{})
  192. diseinfo := make([]map[string]interface{}, 0)
  193. inputMessage["infno"] = "2203" // 交易编码
  194. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  195. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  196. inputData["med_type"] = med_type // 医疗类别 16门诊特殊病
  197. inputData["begntime"] = timeFormatOne // 开始时间
  198. inputData["main_cond_dscr"] = "" // 主要病情描述
  199. inputData["dise_codg"] = "" // 病种编码
  200. inputData["dise_name"] = "" // 病种名称
  201. inputData["birctrl_type"] = "" // 计划生育手术类别
  202. inputData["birctrl_matn_date"] = "" // 计划生育手术或生育日期
  203. diseinfo_sun := make(map[string]interface{})
  204. diseinfo_sun["diag_type"] = "1" // 诊断类别
  205. diseinfo_sun["diag_srt_no"] = "1" // 诊断排序号
  206. diseinfo_sun["diag_code"] = "A04.902" // 诊断代码
  207. diseinfo_sun["diag_name"] = diag // 诊断名称
  208. diseinfo_sun["diag_dept"] = department // 诊断科室
  209. diseinfo_sun["dise_dor_no"] = doctor_id // 诊断医生编码
  210. diseinfo_sun["dise_dor_name"] = doctor // 诊断医生姓名
  211. diseinfo_sun["diag_time"] = timeFormatOne // 诊断时间
  212. diseinfo_sun["vali_flag"] = "1" // 有效标志
  213. diseinfo = append(diseinfo, diseinfo_sun)
  214. input["diseinfo"] = diseinfo
  215. input["mdtrtinfo"] = inputData
  216. inputMessage["input"] = input //交易输入
  217. bytesData, err := json.Marshal(inputMessage)
  218. fmt.Println(string(bytesData))
  219. if err != nil {
  220. fmt.Println(err.Error())
  221. return err.Error()
  222. }
  223. reader := bytes.NewReader(bytesData)
  224. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2203"
  225. request, err := http.NewRequest("POST", url, reader)
  226. if err != nil {
  227. fmt.Println(err.Error())
  228. return err.Error()
  229. }
  230. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  231. request.Header.Set("x-tif-paasid", "test_hosp")
  232. request.Header.Set("x-tif-signature", signature)
  233. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  234. request.Header.Set("x-tif-nonce", nonce)
  235. client := http.Client{}
  236. resp, err := client.Do(request)
  237. if err != nil {
  238. fmt.Println(err.Error())
  239. return err.Error()
  240. }
  241. respBytes, err := ioutil.ReadAll(resp.Body)
  242. if err != nil {
  243. fmt.Println(err.Error())
  244. return err.Error()
  245. }
  246. str := string(respBytes)
  247. fmt.Println(str)
  248. return str
  249. }
  250. type Custom struct {
  251. DetItemFeeSumamt string
  252. Cut string
  253. FeedetlSn string
  254. Price string
  255. MedListCodg string
  256. }
  257. type RequestResult struct {
  258. Output Output `json:"output" form:"output"`
  259. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  260. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  261. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  262. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  263. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  264. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  265. }
  266. type Output struct {
  267. Result Result `json:"result" form:"result"`
  268. }
  269. type Result struct {
  270. BasMednFlag string `json:"bas_medn_flag" form:"bas_medn_flag"`
  271. MedChrgitmType string `json:"med_chrgitm_type" form:"med_chrgitm_type"`
  272. DetItemFeeSumamt int64 `json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  273. HiNegoDrugFlag string `json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  274. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  275. FeedtlSn int64 `json:"feedtl_sn" form:"feedtl_sn"`
  276. UploadDate int64 `json:"upload_date" form:"upload_date"`
  277. AdviceId int64 `json:"advice_id" form:"advice_id"`
  278. Cnt int64 `json:"cnt" form:"cnt"`
  279. Pric float64 `json:"pric" form:"pric"`
  280. PatientId int64 `json:"patient_id" form:"patient_id"`
  281. PricUplmtAmt float64 `json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  282. SelfpayProp float64 `json:"selfpay_prop" form:"selfpay_prop"`
  283. OverlmtAmt float64 `json:"overlmt_amt" form:"overlmt_amt"`
  284. PreselfpayAmt float64 `json:"preselfpay_amt" form:"preselfpay_amt"`
  285. Status int64 `json:"status" form:"status"`
  286. Memo string `json:"memo" form:"memo"`
  287. FeedetlSn string `json:"feedetl_sn" form:"feedetl_sn"`
  288. Mtime int64 `json:"mtime" form:"mtime"`
  289. InscpScpAmt float64 `json:"inscp_scp_amt" form:"inscp_scp_amt"`
  290. DrtReimFlag string `json:"drt_reim_flag" form:"drt_reim_flag"`
  291. Ctime int64 `json:"ctime" form:"ctime"`
  292. ListSpItemFlag string `json:"list_sp_item_flag" form:"list_sp_item_flag"`
  293. ChldMedcFlag string `json:"chld_medc_flag" form:"chld_medc_flag"`
  294. LmtUsedFlag string `json:"lmt_used_flag" form:"lmt_used_flag"`
  295. ChrgitmLv string `json:"chrgitm_lv" form:"chrgitm_lv"`
  296. UserOrgId int64 `json:"user_org_id" form:"user_org_id"`
  297. HisPatientId int64 `json:"his_patient_id" form:"his_patient_id"`
  298. OrderId int64 `json:"order_id" form:"order_id"`
  299. }
  300. // 门诊费用明细信息上传
  301. func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescription, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string) string {
  302. // 生成签名
  303. nonce := GetRandomString(32)
  304. timestamp := time.Now().Unix()
  305. signature := setSignature(timestamp, nonce)
  306. tempTime := time.Unix(timestamp, 0)
  307. //timeFormat := tempTime.Format("20060102150405")
  308. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  309. //chrgBchno := rand.Intn(100000) + 10000
  310. var customs []*Custom
  311. for _, item := range hisPrescription {
  312. if item.Type == 1 { //药品
  313. for _, subItem := range item.HisDoctorAdviceInfo {
  314. //var randNum int
  315. //randNum = rand.Intn(10000) + 1000
  316. cus := &Custom{
  317. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  318. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  319. FeedetlSn: subItem.FeedetlSn,
  320. Price: fmt.Sprintf("%.2f", subItem.Price),
  321. MedListCodg: subItem.MedListCodg,
  322. }
  323. customs = append(customs, cus)
  324. }
  325. }
  326. if item.Type == 2 { //项目
  327. for _, subItem := range item.HisPrescriptionProject {
  328. //var randNum int
  329. //randNum = rand.Intn(10000) + 1000
  330. cus := &Custom{
  331. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  332. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  333. FeedetlSn: subItem.FeedetlSn,
  334. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  335. MedListCodg: subItem.MedListCodg,
  336. }
  337. fmt.Println(cus.FeedetlSn)
  338. customs = append(customs, cus)
  339. }
  340. }
  341. }
  342. // 生成输入报文
  343. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code)
  344. input := make(map[string]interface{})
  345. feedetail := make([]map[string]interface{}, 0)
  346. inputMessage["infno"] = "2204" // 交易编码
  347. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  348. for _, item := range customs {
  349. feedetailInfo := make(map[string]interface{})
  350. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  351. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  352. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  353. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  354. feedetailInfo["dise_codg"] = "" // 病种编码
  355. feedetailInfo["rxno"] = "" // 处方号
  356. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  357. feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间
  358. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  359. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  360. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  361. feedetailInfo["cnt"] = item.Cut // 数量
  362. feedetailInfo["pric"] = item.Price // 单价
  363. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  364. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  365. feedetailInfo["prd_days"] = "0" // 周期天数
  366. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  367. feedetailInfo["bilg_dept_codg"] = "3002" // 开单科室编码
  368. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  369. feedetailInfo["bilg_dr_codg"] = "1002" // 开单医生编码
  370. feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名
  371. feedetailInfo["acord_dept_codg"] = "" // 受单科室编码
  372. feedetailInfo["acord_dept_name"] = "" // 受单科室名称
  373. feedetailInfo["orders_dr_code"] = "" // 受单医生编码
  374. feedetailInfo["orders_dr_name"] = "" // 受单医生姓名
  375. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  376. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  377. feedetailInfo["etip_flag"] = "" // 外检标志
  378. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  379. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  380. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  381. feedetail = append(feedetail, feedetailInfo)
  382. }
  383. input["feedetail"] = feedetail
  384. inputMessage["input"] = input //交易输入
  385. bytesData, err := json.Marshal(inputMessage)
  386. fmt.Println("----------")
  387. fmt.Println(string(bytesData))
  388. fmt.Println("----------")
  389. if err != nil {
  390. fmt.Println(err.Error())
  391. return ""
  392. }
  393. reader := bytes.NewReader(bytesData)
  394. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204"
  395. request, err := http.NewRequest("POST", url, reader)
  396. if err != nil {
  397. fmt.Println(err.Error())
  398. return ""
  399. }
  400. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  401. request.Header.Set("x-tif-paasid", "test_hosp")
  402. request.Header.Set("x-tif-signature", signature)
  403. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  404. request.Header.Set("x-tif-nonce", nonce)
  405. client := http.Client{}
  406. resp, err := client.Do(request)
  407. if err != nil {
  408. fmt.Println(err.Error())
  409. return ""
  410. }
  411. respBytes, err := ioutil.ReadAll(resp.Body)
  412. if err != nil {
  413. fmt.Println(err.Error())
  414. return ""
  415. }
  416. return string(respBytes)
  417. //var result RequestResult
  418. //json.Unmarshal(respBytes, &result)
  419. //return &result
  420. }
  421. // 门诊费用明细信息撤销
  422. func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string) string {
  423. // 生成签名
  424. nonce := GetRandomString(32)
  425. timestamp := time.Now().Unix()
  426. signature := setSignature(timestamp, nonce)
  427. // 生成输入报文
  428. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  429. input := make(map[string]interface{})
  430. inputData := make(map[string]interface{})
  431. inputMessage["infno"] = "2205" // 交易编码
  432. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  433. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  434. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  435. input["data"] = inputData
  436. inputMessage["input"] = input //交易输入
  437. bytesData, err := json.Marshal(inputMessage)
  438. fmt.Println(string(bytesData))
  439. if err != nil {
  440. fmt.Println(err.Error())
  441. return err.Error()
  442. }
  443. reader := bytes.NewReader(bytesData)
  444. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  445. request, err := http.NewRequest("POST", url, reader)
  446. fmt.Println(err)
  447. fmt.Println(request)
  448. if err != nil {
  449. fmt.Println(err.Error())
  450. return err.Error()
  451. }
  452. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  453. request.Header.Set("x-tif-paasid", "test_hosp")
  454. request.Header.Set("x-tif-signature", signature)
  455. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  456. request.Header.Set("x-tif-nonce", nonce)
  457. client := http.Client{}
  458. resp, err := client.Do(request)
  459. if err != nil {
  460. fmt.Println(err.Error())
  461. return err.Error()
  462. }
  463. respBytes, err := ioutil.ReadAll(resp.Body)
  464. if err != nil {
  465. fmt.Println(err.Error())
  466. return err.Error()
  467. }
  468. str := string(respBytes)
  469. fmt.Println(str)
  470. return str
  471. }
  472. // 门诊预结算
  473. func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string) string {
  474. // 生成签名
  475. nonce := GetRandomString(32)
  476. timestamp := time.Now().Unix()
  477. signature := setSignature(timestamp, nonce)
  478. // 生成输入报文
  479. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  480. input := make(map[string]interface{})
  481. inputData := make(map[string]interface{})
  482. inputMessage["infno"] = "2206" // 交易编码
  483. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  484. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型,
  485. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  486. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  487. inputData["medfee_sumamt"] = total // 医疗费总额
  488. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  489. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  490. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  491. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  492. inputData["insutype"] = insutype // 险种类型
  493. input["data"] = inputData
  494. inputMessage["input"] = input //交易输入
  495. bytesData, err := json.Marshal(inputMessage)
  496. fmt.Println(string(bytesData))
  497. if err != nil {
  498. fmt.Println(err.Error())
  499. return err.Error()
  500. }
  501. reader := bytes.NewReader(bytesData)
  502. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206"
  503. request, err := http.NewRequest("POST", url, reader)
  504. if err != nil {
  505. fmt.Println(err.Error())
  506. return err.Error()
  507. }
  508. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  509. request.Header.Set("x-tif-paasid", "test_hosp")
  510. request.Header.Set("x-tif-signature", signature)
  511. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  512. request.Header.Set("x-tif-nonce", nonce)
  513. client := http.Client{}
  514. resp, err := client.Do(request)
  515. if err != nil {
  516. fmt.Println(err.Error())
  517. return err.Error()
  518. }
  519. respBytes, err := ioutil.ReadAll(resp.Body)
  520. if err != nil {
  521. fmt.Println(err.Error())
  522. return err.Error()
  523. }
  524. str := string(respBytes)
  525. fmt.Println(str)
  526. return str
  527. }
  528. // 门诊结算
  529. func Gdyb2207(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, fixmedins_code string) string {
  530. // 生成签名
  531. nonce := GetRandomString(32)
  532. timestamp := time.Now().Unix()
  533. signature := setSignature(timestamp, nonce)
  534. // 生成输入报文
  535. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code)
  536. input := make(map[string]interface{})
  537. inputData := make(map[string]interface{})
  538. inputMessage["infno"] = "2207" // 交易编码
  539. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  540. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  541. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  542. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  543. inputData["medfee_sumamt"] = total // 医疗费总额
  544. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  545. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  546. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  547. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  548. inputData["insutype"] = insutype // 险种类型
  549. inputData["invono"] = "" // 发票号
  550. input["data"] = inputData
  551. inputMessage["input"] = input //交易输入
  552. bytesData, err := json.Marshal(inputMessage)
  553. fmt.Println(string(bytesData))
  554. if err != nil {
  555. fmt.Println(err.Error())
  556. return err.Error()
  557. }
  558. reader := bytes.NewReader(bytesData)
  559. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  560. request, err := http.NewRequest("POST", url, reader)
  561. if err != nil {
  562. fmt.Println(err.Error())
  563. return err.Error()
  564. }
  565. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  566. request.Header.Set("x-tif-paasid", "test_hosp")
  567. request.Header.Set("x-tif-signature", signature)
  568. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  569. request.Header.Set("x-tif-nonce", nonce)
  570. client := http.Client{}
  571. resp, err := client.Do(request)
  572. if err != nil {
  573. fmt.Println(err.Error())
  574. return err.Error()
  575. }
  576. respBytes, err := ioutil.ReadAll(resp.Body)
  577. if err != nil {
  578. fmt.Println(err.Error())
  579. return err.Error()
  580. }
  581. str := string(respBytes)
  582. fmt.Println(str)
  583. return str
  584. }
  585. // 门诊结算撤销
  586. func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doctor string) string {
  587. // 生成签名
  588. nonce := GetRandomString(32)
  589. timestamp := time.Now().Unix()
  590. signature := setSignature(timestamp, nonce)
  591. // 生成输入报文
  592. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  593. input := make(map[string]interface{})
  594. inputData := make(map[string]interface{})
  595. inputMessage["infno"] = "2208" // 交易编码
  596. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  597. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  598. inputData["setl_id"] = setlId // 结算 ID
  599. input["data"] = inputData
  600. inputMessage["input"] = input //交易输入
  601. bytesData, err := json.Marshal(inputMessage)
  602. fmt.Println(string(bytesData))
  603. if err != nil {
  604. fmt.Println(err.Error())
  605. return err.Error()
  606. }
  607. reader := bytes.NewReader(bytesData)
  608. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  609. request, err := http.NewRequest("POST", url, reader)
  610. if err != nil {
  611. fmt.Println(err.Error())
  612. return err.Error()
  613. }
  614. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  615. request.Header.Set("x-tif-paasid", "test_hosp")
  616. request.Header.Set("x-tif-signature", signature)
  617. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  618. request.Header.Set("x-tif-nonce", nonce)
  619. client := http.Client{}
  620. resp, err := client.Do(request)
  621. if err != nil {
  622. fmt.Println(err.Error())
  623. return err.Error()
  624. }
  625. respBytes, err := ioutil.ReadAll(resp.Body)
  626. if err != nil {
  627. fmt.Println(err.Error())
  628. return err.Error()
  629. }
  630. str := string(respBytes)
  631. fmt.Println(str)
  632. return str
  633. }
  634. // 门诊结算撤销
  635. //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
  636. // // 生成签名
  637. // nonce := GetRandomString(32)
  638. // timestamp := time.Now().Unix()
  639. // signature := setSignature(timestamp, nonce)
  640. //
  641. // // 生成输入报文
  642. // inputMessage := SetInputMessage(nonce, timestamp)
  643. // input := make(map[string]interface{})
  644. // inputData := make(map[string]interface{})
  645. // inputMessage["infno"] = "4101" // 交易编码
  646. //
  647. // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回)
  648. // inputData["setl_id"] = setlId // 结算 ID 必填
  649. // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填
  650. // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填
  651. // inputData["hi_setl_lv"] = "" // 医保结算等级
  652. // inputData["hi_no"] = "" // 医保编号
  653. // inputData["medcasno"] = "" // 病案号 必填
  654. // inputData["dcla_time"] = "" // 申报时间 必填
  655. // inputData["psn_name"] = "" // 人员姓名 必填
  656. // inputData["gend"] = "" // 性别 必填
  657. // inputData["brdy"] = "" // 出生日期 必填
  658. // inputData["age"] = "" // 年龄 必填
  659. // inputData["ntly"] = "" // 国籍 必填
  660. // inputData["nwb_age"] = "" // 年龄 必填
  661. // inputData["naty"] = "" // 民族 必填
  662. // inputData["patn_cert_type"] = "" // 患者证件类别 必填
  663. // inputData["certno"] = "" // 证件号码 必填
  664. // inputData["prfs"] = "" // 职业 必填
  665. // inputData["curr_addr"] = "" // 现住址 必填
  666. // inputData["emp_name"] = "" // 单位名称 必填
  667. // inputData["emp_addr"] = "" // 单位地址 必填
  668. // inputData["emp_tel"] = "" // 单位电话 必填
  669. // inputData["poscode"] = "" // 邮编 必填
  670. // inputData["coner_name"] = "" // 联系人姓名 必填
  671. // inputData["patn_rlts"] = "" // 与患者关系 必填
  672. // inputData["coner_addr"] = "" // 联系人地址 必填
  673. // inputData["coner_tel"] = "" // 联系人电话 必填
  674. // inputData["hi_type"] = "" // 医保类型 必填
  675. // inputData["insuplc"] = "" // 参保地 必填
  676. // inputData["sp_psn_type"] = "" // 特殊人员类型 必填
  677. // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填
  678. // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填
  679. // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填
  680. // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填
  681. // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填
  682. // inputData["ipt_med_type"] = "" // 住院医疗类型 必填
  683. // inputData["adm_way"] = "" // 入院途径 必填
  684. // inputData["trt_type"] = "" // 治疗类别 必填
  685. // inputData["adm_time"] = "" // 入院时间 必填
  686. // inputData["adm_caty"] = "" // 入院科别 必填
  687. // inputData["refldept_dept"] = "" // 转科科别 必填
  688. // inputData["dscg_time"] = "" // 出院时间 必填
  689. // inputData["dscg_caty"] = "" // 出院科别 必填
  690. // inputData["act_ipt_days"] = "" // 实际住院天数 必填
  691. // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填
  692. // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填
  693. // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填
  694. // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填
  695. // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填
  696. // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填
  697. // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填
  698. // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填
  699. // inputData["bld_cat"] = "" // 输血品种 必填
  700. // inputData["bld_amt"] = "" // 输血量 必填
  701. // inputData["bld_unt"] = "" // 输血计量单位 必填
  702. // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填
  703. // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填
  704. // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填
  705. // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填
  706. // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填
  707. // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填
  708. // inputData["bill_code"] = "" // 票据代码 必填
  709. // inputData["bill_no"] = "" // 票据号码 必填
  710. // inputData["biz_sn"] = "" // 业务流水号 必填
  711. // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填
  712. // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填
  713. // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填
  714. // inputData["chfpdr_code"] = "" // 主诊医师代码 必填
  715. // inputData["setl_begn_date"] = "" // 结算开始日期 必填
  716. // inputData["setl_end_date"] = "" // 结算结束日期 必填
  717. // inputData["psn_selfpay"] = "" // 个人自付 必填
  718. // inputData["psn_ownpay"] = "" // 个人自费 必填
  719. // inputData["acct_pay"] = "" // 个人账户支出 必填
  720. // inputData["hi_paymtd"] = "" // 医保支付方式 必填
  721. // inputData["hsorg"] = "" // 医保机构 必填
  722. // inputData["hsorg_opter"] = "" // 医保机构经办人 必填
  723. // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填
  724. // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填
  725. //
  726. // payinfo := make([]map[string]interface{},0) // 基金支付信息
  727. // payinfotemp := make(map[string]interface{})
  728. // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填
  729. // payinfotemp["fund_payamt"] = "" // 基金支付金额
  730. // payinfo = append(payinfo,payinfotemp)
  731. //
  732. // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
  733. // opspdiseinfotemp := make(map[string]interface{})
  734. // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填
  735. // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填
  736. // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  737. // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  738. // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
  739. //
  740. // diseinfo := make([]map[string]interface{},0) // 住院诊断信息
  741. // diseinfotemp := make(map[string]interface{})
  742. // diseinfotemp["diag_type"] = "" // 诊断类别 必填
  743. // diseinfotemp["diag_code"] = "" // 诊断代码 必填
  744. // diseinfotemp["diag_name"] = "" // 诊断名称 必填
  745. // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填
  746. // diseinfo = append(diseinfo,diseinfotemp)
  747. //
  748. // iteminfo := make([]map[string]interface{},0) // 住院诊断信息
  749. // iteminfotemp := make(map[string]interface{})
  750. // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填
  751. // iteminfotemp["amt"] = "" // 金额 必填
  752. // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填
  753. // iteminfotemp["clab_amt"] = "" // 乙类金额 必填
  754. // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填
  755. // iteminfotemp["oth_amt"] = "" // 其他金额 必填
  756. // iteminfo = append(iteminfo,iteminfotemp)
  757. //
  758. // oprninfo := make([]map[string]interface{},0) // 手术操作信息
  759. // oprninfotemp := make(map[string]interface{})
  760. // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填
  761. // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  762. // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  763. // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填
  764. // oprninfotemp["anst_way"] = "" // 麻醉方式 必填
  765. // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填
  766. // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填
  767. // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填
  768. // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填
  769. // oprninfo = append(oprninfo,iteminfotemp)
  770. //
  771. // icuinfo := make([]map[string]interface{},0) // 重症监护信息
  772. // icuinfotemp := make(map[string]interface{})
  773. // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填
  774. // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填
  775. // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填
  776. // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填
  777. // icuinfo = append(icuinfo,iteminfotemp)
  778. //
  779. //
  780. //
  781. //
  782. // input["setlinfo"] = inputData
  783. // input["payinfo"] = payinfo
  784. // input["opspdiseinfo"] = opspdiseinfo
  785. // input["diseinfo"] = diseinfo
  786. // input["iteminfo"] = iteminfo
  787. // input["oprninfo"] = oprninfo
  788. // input["icuinfo"] = icuinfo
  789. // inputMessage["input"] = input //交易输入
  790. //
  791. // bytesData, err := json.Marshal(inputMessage)
  792. // fmt.Println(string(bytesData))
  793. // if err != nil {
  794. // fmt.Println(err.Error())
  795. // return err.Error()
  796. // }
  797. // reader := bytes.NewReader(bytesData)
  798. //
  799. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  800. // request, err := http.NewRequest("POST", url, reader)
  801. // if err != nil {
  802. // fmt.Println(err.Error())
  803. // return err.Error()
  804. // }
  805. //
  806. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  807. // request.Header.Set("x-tif-paasid", "test_hosp")
  808. // request.Header.Set("x-tif-signature", signature)
  809. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  810. // request.Header.Set("x-tif-nonce", nonce)
  811. //
  812. // client := http.Client{}
  813. // resp, err := client.Do(request)
  814. // if err != nil {
  815. // fmt.Println(err.Error())
  816. // return err.Error()
  817. // }
  818. // respBytes, err := ioutil.ReadAll(resp.Body)
  819. // if err != nil {
  820. // fmt.Println(err.Error())
  821. // return err.Error()
  822. // }
  823. // str := string(respBytes)
  824. // fmt.Println(str)
  825. // return str
  826. //}
  827. // 生成签名
  828. func setSignature(timestamp int64, nonce string) string {
  829. str := strconv.FormatInt(timestamp, 10) + SceretKey + nonce + strconv.FormatInt(timestamp, 10)
  830. hash := sha256.New()
  831. //输入数据
  832. hash.Write([]byte(str))
  833. //计算哈希值
  834. bytes := hash.Sum(nil)
  835. //将字符串编码为16进制格式,返回字符串
  836. hashCode := hex.EncodeToString(bytes)
  837. //返回哈希值
  838. return hashCode
  839. }
  840. // 生成随机字符串
  841. func GetRandomString(l int) string {
  842. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  843. bytes := []byte(str)
  844. result := []byte{}
  845. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  846. for i := 0; i < l; i++ {
  847. result = append(result, bytes[r.Intn(len(bytes))])
  848. }
  849. return string(result)
  850. }
  851. // 生成基础报文
  852. func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string) map[string]interface{} {
  853. // 生成签名
  854. tempTime := time.Unix(timestamp, 0)
  855. timeFormat := tempTime.Format("20060102150405")
  856. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  857. randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  858. // 生成输入报文
  859. inputMessage := make(map[string]interface{})
  860. inputMessage["infno"] = "1101" // 交易编码
  861. inputMessage["msgid"] = fixmedins_code + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID
  862. inputMessage["mdtrtarea_admvs"] = "440200" // 就医地医保区划
  863. inputMessage["insuplc_admdvs"] = "440200" // 参保地医保区划
  864. inputMessage["recer_sys_code"] = "01" // 接收方系统代码
  865. inputMessage["dev_no"] = "" // 设备编号
  866. inputMessage["dev_safe_info"] = "" // 设备安全信息
  867. inputMessage["cainfo"] = "" // 数字签名信息
  868. inputMessage["signtype"] = "" // 签名类型
  869. inputMessage["infver"] = "V1.1" // 接收方系统代码
  870. inputMessage["opter_type"] = "1" // 经办人类别
  871. inputMessage["opter"] = "mockuser" // 经办人
  872. inputMessage["opter_name"] = doctor // 经办人姓名
  873. inputMessage["inf_time"] = timeFormatOne // 交易时间
  874. inputMessage["fixmedins_code"] = fixmedins_code // 定点医药机构编号
  875. inputMessage["fixmedins_name"] = org_name //定点医药机构名称
  876. inputMessage["sign_no"] = "" //交易签到流水号
  877. return inputMessage
  878. }
  879. func Gdyb1201(psnNo string, org_name string, doctor string) string {
  880. // 生成签名
  881. nonce := GetRandomString(32)
  882. timestamp := time.Now().Unix()
  883. signature := setSignature(timestamp, nonce)
  884. // 生成输入报文
  885. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  886. input := make(map[string]interface{})
  887. inputData := make(map[string]interface{})
  888. inputMessage["infno"] = "1201" // 交易编码
  889. inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回)
  890. inputData["fixmedins_name"] = org_name // 人员编号 (来自1101接口返回)
  891. inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回)
  892. input["medinsinfo"] = inputData
  893. inputMessage["input"] = input //交易输入
  894. bytesData, err := json.Marshal(inputMessage)
  895. fmt.Println(string(bytesData))
  896. if err != nil {
  897. fmt.Println(err.Error())
  898. return err.Error()
  899. }
  900. reader := bytes.NewReader(bytesData)
  901. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201"
  902. request, err := http.NewRequest("POST", url, reader)
  903. if err != nil {
  904. fmt.Println(err.Error())
  905. return err.Error()
  906. }
  907. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  908. request.Header.Set("x-tif-paasid", "test_hosp")
  909. request.Header.Set("x-tif-signature", signature)
  910. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  911. request.Header.Set("x-tif-nonce", nonce)
  912. client := http.Client{}
  913. resp, err := client.Do(request)
  914. if err != nil {
  915. fmt.Println(err.Error())
  916. return err.Error()
  917. }
  918. respBytes, err := ioutil.ReadAll(resp.Body)
  919. if err != nil {
  920. fmt.Println(err.Error())
  921. return err.Error()
  922. }
  923. str := string(respBytes)
  924. fmt.Println(str)
  925. return str
  926. }