gdyb_service.go 41KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  21. // 生成签名
  22. nonce := GetRandomString(32)
  23. timestamp := time.Now().Unix()
  24. signature := setSignature(timestamp, nonce, secret_key)
  25. // 生成输入报文
  26. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  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, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  74. // 生成签名
  75. nonce := GetRandomString(32)
  76. timestamp := time.Now().Unix()
  77. signature := setSignature(timestamp, nonce, secret_key)
  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, insuplc_admdvs, mdtrtarea_admvs)
  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"] = doctor_id // 医师编码
  92. inputData["dr_name"] = doctor // 医师姓名
  93. inputData["dept_code"] = dept_code // 科室编码
  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, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  133. // 生成签名
  134. nonce := GetRandomString(32)
  135. timestamp := time.Now().Unix()
  136. signature := setSignature(timestamp, nonce, secret_key)
  137. // 生成输入报文
  138. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", insuplc_admdvs, mdtrtarea_admvs)
  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, diag_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  182. // 生成签名
  183. nonce := GetRandomString(32)
  184. timestamp := time.Now().Unix()
  185. signature := setSignature(timestamp, nonce, secret_key)
  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, insuplc_admdvs, mdtrtarea_admvs)
  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"] = diag_code // 诊断代码
  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, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  302. // 生成签名
  303. nonce := GetRandomString(32)
  304. timestamp := time.Now().Unix()
  305. signature := setSignature(timestamp, nonce, secret_key)
  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. if len(subItem.MedListCodg) > 0 {
  315. //var randNum int
  316. //randNum = rand.Intn(10000) + 1000
  317. cus := &Custom{
  318. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  319. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  320. FeedetlSn: subItem.FeedetlSn,
  321. Price: fmt.Sprintf("%.2f", subItem.Price),
  322. MedListCodg: subItem.MedListCodg,
  323. }
  324. customs = append(customs, cus)
  325. }
  326. }
  327. }
  328. if item.Type == 2 { //项目
  329. for _, subItem := range item.HisPrescriptionProject {
  330. //var randNum int
  331. //randNum = rand.Intn(10000) + 1000
  332. if len(subItem.MedListCodg) > 0 {
  333. cus := &Custom{
  334. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  335. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  336. FeedetlSn: subItem.FeedetlSn,
  337. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  338. MedListCodg: subItem.MedListCodg,
  339. }
  340. customs = append(customs, cus)
  341. }
  342. }
  343. }
  344. for _, subItem := range item.HisAdditionalCharge {
  345. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  346. cus := &Custom{
  347. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  348. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  349. FeedetlSn: subItem.FeedetlSn,
  350. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  351. MedListCodg: subItem.XtHisAddtionConfig.Code,
  352. }
  353. customs = append(customs, cus)
  354. }
  355. }
  356. }
  357. // 生成输入报文
  358. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  359. input := make(map[string]interface{})
  360. feedetail := make([]map[string]interface{}, 0)
  361. inputMessage["infno"] = "2204" // 交易编码
  362. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  363. for _, item := range customs {
  364. feedetailInfo := make(map[string]interface{})
  365. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  366. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  367. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  368. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  369. feedetailInfo["dise_codg"] = "" // 病种编码
  370. feedetailInfo["rxno"] = "" // 处方号
  371. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  372. feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间
  373. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  374. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  375. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  376. feedetailInfo["cnt"] = item.Cut // 数量
  377. feedetailInfo["pric"] = item.Price // 单价
  378. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  379. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  380. feedetailInfo["prd_days"] = "0" // 周期天数
  381. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  382. feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码
  383. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  384. feedetailInfo["bilg_dr_codg"] = doctor_id // 开单医生编码
  385. feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名
  386. feedetailInfo["acord_dept_codg"] = "" // 受单科室编码
  387. feedetailInfo["acord_dept_name"] = "" // 受单科室名称
  388. feedetailInfo["orders_dr_code"] = "" // 受单医生编码
  389. feedetailInfo["orders_dr_name"] = "" // 受单医生姓名
  390. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  391. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  392. feedetailInfo["etip_flag"] = "" // 外检标志
  393. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  394. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  395. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  396. feedetail = append(feedetail, feedetailInfo)
  397. }
  398. input["feedetail"] = feedetail
  399. inputMessage["input"] = input //交易输入
  400. bytesData, err := json.Marshal(inputMessage)
  401. fmt.Println("----------")
  402. fmt.Println(string(bytesData))
  403. fmt.Println("----------")
  404. if err != nil {
  405. fmt.Println(err.Error())
  406. return ""
  407. }
  408. reader := bytes.NewReader(bytesData)
  409. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204"
  410. request, err := http.NewRequest("POST", url, reader)
  411. if err != nil {
  412. fmt.Println(err.Error())
  413. return ""
  414. }
  415. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  416. request.Header.Set("x-tif-paasid", "test_hosp")
  417. request.Header.Set("x-tif-signature", signature)
  418. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  419. request.Header.Set("x-tif-nonce", nonce)
  420. client := http.Client{}
  421. resp, err := client.Do(request)
  422. if err != nil {
  423. fmt.Println(err.Error())
  424. return ""
  425. }
  426. respBytes, err := ioutil.ReadAll(resp.Body)
  427. if err != nil {
  428. fmt.Println(err.Error())
  429. return ""
  430. }
  431. return string(respBytes)
  432. //var result RequestResult
  433. //json.Unmarshal(respBytes, &result)
  434. //return &result
  435. }
  436. // 门诊费用明细信息撤销
  437. func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  438. // 生成签名
  439. nonce := GetRandomString(32)
  440. timestamp := time.Now().Unix()
  441. signature := setSignature(timestamp, nonce, secret_key)
  442. // 生成输入报文
  443. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", insuplc_admdvs, mdtrtarea_admvs)
  444. input := make(map[string]interface{})
  445. inputData := make(map[string]interface{})
  446. inputMessage["infno"] = "2205" // 交易编码
  447. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  448. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  449. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  450. input["data"] = inputData
  451. inputMessage["input"] = input //交易输入
  452. bytesData, err := json.Marshal(inputMessage)
  453. fmt.Println(string(bytesData))
  454. if err != nil {
  455. fmt.Println(err.Error())
  456. return err.Error()
  457. }
  458. reader := bytes.NewReader(bytesData)
  459. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  460. request, err := http.NewRequest("POST", url, reader)
  461. fmt.Println(err)
  462. fmt.Println(request)
  463. if err != nil {
  464. fmt.Println(err.Error())
  465. return err.Error()
  466. }
  467. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  468. request.Header.Set("x-tif-paasid", "test_hosp")
  469. request.Header.Set("x-tif-signature", signature)
  470. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  471. request.Header.Set("x-tif-nonce", nonce)
  472. client := http.Client{}
  473. resp, err := client.Do(request)
  474. if err != nil {
  475. fmt.Println(err.Error())
  476. return err.Error()
  477. }
  478. respBytes, err := ioutil.ReadAll(resp.Body)
  479. if err != nil {
  480. fmt.Println(err.Error())
  481. return err.Error()
  482. }
  483. str := string(respBytes)
  484. fmt.Println(str)
  485. return str
  486. }
  487. // 门诊预结算
  488. func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, secret_key string) string {
  489. // 生成签名
  490. nonce := GetRandomString(32)
  491. timestamp := time.Now().Unix()
  492. signature := setSignature(timestamp, nonce, secret_key)
  493. // 生成输入报文
  494. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", "", "")
  495. input := make(map[string]interface{})
  496. inputData := make(map[string]interface{})
  497. inputMessage["infno"] = "2206" // 交易编码
  498. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  499. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型,
  500. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  501. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  502. inputData["medfee_sumamt"] = total // 医疗费总额
  503. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  504. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  505. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  506. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  507. inputData["insutype"] = insutype // 险种类型
  508. input["data"] = inputData
  509. inputMessage["input"] = input //交易输入
  510. bytesData, err := json.Marshal(inputMessage)
  511. fmt.Println(string(bytesData))
  512. if err != nil {
  513. fmt.Println(err.Error())
  514. return err.Error()
  515. }
  516. reader := bytes.NewReader(bytesData)
  517. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206"
  518. request, err := http.NewRequest("POST", url, reader)
  519. if err != nil {
  520. fmt.Println(err.Error())
  521. return err.Error()
  522. }
  523. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  524. request.Header.Set("x-tif-paasid", "test_hosp")
  525. request.Header.Set("x-tif-signature", signature)
  526. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  527. request.Header.Set("x-tif-nonce", nonce)
  528. client := http.Client{}
  529. resp, err := client.Do(request)
  530. if err != nil {
  531. fmt.Println(err.Error())
  532. return err.Error()
  533. }
  534. respBytes, err := ioutil.ReadAll(resp.Body)
  535. if err != nil {
  536. fmt.Println(err.Error())
  537. return err.Error()
  538. }
  539. str := string(respBytes)
  540. fmt.Println(str)
  541. return str
  542. }
  543. // 门诊结算
  544. 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 {
  545. // 生成签名
  546. nonce := GetRandomString(32)
  547. timestamp := time.Now().Unix()
  548. signature := setSignature(timestamp, nonce, secret_key)
  549. // 生成输入报文
  550. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  551. input := make(map[string]interface{})
  552. inputData := make(map[string]interface{})
  553. inputMessage["infno"] = "2207" // 交易编码
  554. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  555. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  556. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  557. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  558. inputData["medfee_sumamt"] = total // 医疗费总额
  559. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  560. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  561. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  562. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  563. inputData["insutype"] = insutype // 险种类型
  564. inputData["invono"] = "" // 发票号
  565. input["data"] = inputData
  566. inputMessage["input"] = input //交易输入
  567. bytesData, err := json.Marshal(inputMessage)
  568. fmt.Println(string(bytesData))
  569. if err != nil {
  570. fmt.Println(err.Error())
  571. return err.Error()
  572. }
  573. reader := bytes.NewReader(bytesData)
  574. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  575. request, err := http.NewRequest("POST", url, reader)
  576. if err != nil {
  577. fmt.Println(err.Error())
  578. return err.Error()
  579. }
  580. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  581. request.Header.Set("x-tif-paasid", "test_hosp")
  582. request.Header.Set("x-tif-signature", signature)
  583. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  584. request.Header.Set("x-tif-nonce", nonce)
  585. client := http.Client{}
  586. resp, err := client.Do(request)
  587. if err != nil {
  588. fmt.Println(err.Error())
  589. return err.Error()
  590. }
  591. respBytes, err := ioutil.ReadAll(resp.Body)
  592. if err != nil {
  593. fmt.Println(err.Error())
  594. return err.Error()
  595. }
  596. str := string(respBytes)
  597. fmt.Println(str)
  598. return str
  599. }
  600. // 门诊结算撤销
  601. func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doctor string, secret_key string) string {
  602. // 生成签名
  603. nonce := GetRandomString(32)
  604. timestamp := time.Now().Unix()
  605. signature := setSignature(timestamp, nonce, secret_key)
  606. // 生成输入报文
  607. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", "", "")
  608. input := make(map[string]interface{})
  609. inputData := make(map[string]interface{})
  610. inputMessage["infno"] = "2208" // 交易编码
  611. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  612. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  613. inputData["setl_id"] = setlId // 结算 ID
  614. input["data"] = inputData
  615. inputMessage["input"] = input //交易输入
  616. bytesData, err := json.Marshal(inputMessage)
  617. fmt.Println(string(bytesData))
  618. if err != nil {
  619. fmt.Println(err.Error())
  620. return err.Error()
  621. }
  622. reader := bytes.NewReader(bytesData)
  623. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  624. request, err := http.NewRequest("POST", url, reader)
  625. if err != nil {
  626. fmt.Println(err.Error())
  627. return err.Error()
  628. }
  629. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  630. request.Header.Set("x-tif-paasid", "test_hosp")
  631. request.Header.Set("x-tif-signature", signature)
  632. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  633. request.Header.Set("x-tif-nonce", nonce)
  634. client := http.Client{}
  635. resp, err := client.Do(request)
  636. if err != nil {
  637. fmt.Println(err.Error())
  638. return err.Error()
  639. }
  640. respBytes, err := ioutil.ReadAll(resp.Body)
  641. if err != nil {
  642. fmt.Println(err.Error())
  643. return err.Error()
  644. }
  645. str := string(respBytes)
  646. fmt.Println(str)
  647. return str
  648. }
  649. // 门诊结算撤销
  650. //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
  651. // // 生成签名
  652. // nonce := GetRandomString(32)
  653. // timestamp := time.Now().Unix()
  654. // signature := setSignature(timestamp, nonce)
  655. //
  656. // // 生成输入报文
  657. // inputMessage := SetInputMessage(nonce, timestamp)
  658. // input := make(map[string]interface{})
  659. // inputData := make(map[string]interface{})
  660. // inputMessage["infno"] = "4101" // 交易编码
  661. //
  662. // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回)
  663. // inputData["setl_id"] = setlId // 结算 ID 必填
  664. // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填
  665. // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填
  666. // inputData["hi_setl_lv"] = "" // 医保结算等级
  667. // inputData["hi_no"] = "" // 医保编号
  668. // inputData["medcasno"] = "" // 病案号 必填
  669. // inputData["dcla_time"] = "" // 申报时间 必填
  670. // inputData["psn_name"] = "" // 人员姓名 必填
  671. // inputData["gend"] = "" // 性别 必填
  672. // inputData["brdy"] = "" // 出生日期 必填
  673. // inputData["age"] = "" // 年龄 必填
  674. // inputData["ntly"] = "" // 国籍 必填
  675. // inputData["nwb_age"] = "" // 年龄 必填
  676. // inputData["naty"] = "" // 民族 必填
  677. // inputData["patn_cert_type"] = "" // 患者证件类别 必填
  678. // inputData["certno"] = "" // 证件号码 必填
  679. // inputData["prfs"] = "" // 职业 必填
  680. // inputData["curr_addr"] = "" // 现住址 必填
  681. // inputData["emp_name"] = "" // 单位名称 必填
  682. // inputData["emp_addr"] = "" // 单位地址 必填
  683. // inputData["emp_tel"] = "" // 单位电话 必填
  684. // inputData["poscode"] = "" // 邮编 必填
  685. // inputData["coner_name"] = "" // 联系人姓名 必填
  686. // inputData["patn_rlts"] = "" // 与患者关系 必填
  687. // inputData["coner_addr"] = "" // 联系人地址 必填
  688. // inputData["coner_tel"] = "" // 联系人电话 必填
  689. // inputData["hi_type"] = "" // 医保类型 必填
  690. // inputData["insuplc"] = "" // 参保地 必填
  691. // inputData["sp_psn_type"] = "" // 特殊人员类型 必填
  692. // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填
  693. // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填
  694. // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填
  695. // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填
  696. // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填
  697. // inputData["ipt_med_type"] = "" // 住院医疗类型 必填
  698. // inputData["adm_way"] = "" // 入院途径 必填
  699. // inputData["trt_type"] = "" // 治疗类别 必填
  700. // inputData["adm_time"] = "" // 入院时间 必填
  701. // inputData["adm_caty"] = "" // 入院科别 必填
  702. // inputData["refldept_dept"] = "" // 转科科别 必填
  703. // inputData["dscg_time"] = "" // 出院时间 必填
  704. // inputData["dscg_caty"] = "" // 出院科别 必填
  705. // inputData["act_ipt_days"] = "" // 实际住院天数 必填
  706. // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填
  707. // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填
  708. // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填
  709. // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填
  710. // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填
  711. // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填
  712. // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填
  713. // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填
  714. // inputData["bld_cat"] = "" // 输血品种 必填
  715. // inputData["bld_amt"] = "" // 输血量 必填
  716. // inputData["bld_unt"] = "" // 输血计量单位 必填
  717. // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填
  718. // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填
  719. // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填
  720. // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填
  721. // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填
  722. // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填
  723. // inputData["bill_code"] = "" // 票据代码 必填
  724. // inputData["bill_no"] = "" // 票据号码 必填
  725. // inputData["biz_sn"] = "" // 业务流水号 必填
  726. // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填
  727. // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填
  728. // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填
  729. // inputData["chfpdr_code"] = "" // 主诊医师代码 必填
  730. // inputData["setl_begn_date"] = "" // 结算开始日期 必填
  731. // inputData["setl_end_date"] = "" // 结算结束日期 必填
  732. // inputData["psn_selfpay"] = "" // 个人自付 必填
  733. // inputData["psn_ownpay"] = "" // 个人自费 必填
  734. // inputData["acct_pay"] = "" // 个人账户支出 必填
  735. // inputData["hi_paymtd"] = "" // 医保支付方式 必填
  736. // inputData["hsorg"] = "" // 医保机构 必填
  737. // inputData["hsorg_opter"] = "" // 医保机构经办人 必填
  738. // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填
  739. // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填
  740. //
  741. // payinfo := make([]map[string]interface{},0) // 基金支付信息
  742. // payinfotemp := make(map[string]interface{})
  743. // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填
  744. // payinfotemp["fund_payamt"] = "" // 基金支付金额
  745. // payinfo = append(payinfo,payinfotemp)
  746. //
  747. // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
  748. // opspdiseinfotemp := make(map[string]interface{})
  749. // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填
  750. // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填
  751. // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  752. // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  753. // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
  754. //
  755. // diseinfo := make([]map[string]interface{},0) // 住院诊断信息
  756. // diseinfotemp := make(map[string]interface{})
  757. // diseinfotemp["diag_type"] = "" // 诊断类别 必填
  758. // diseinfotemp["diag_code"] = "" // 诊断代码 必填
  759. // diseinfotemp["diag_name"] = "" // 诊断名称 必填
  760. // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填
  761. // diseinfo = append(diseinfo,diseinfotemp)
  762. //
  763. // iteminfo := make([]map[string]interface{},0) // 住院诊断信息
  764. // iteminfotemp := make(map[string]interface{})
  765. // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填
  766. // iteminfotemp["amt"] = "" // 金额 必填
  767. // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填
  768. // iteminfotemp["clab_amt"] = "" // 乙类金额 必填
  769. // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填
  770. // iteminfotemp["oth_amt"] = "" // 其他金额 必填
  771. // iteminfo = append(iteminfo,iteminfotemp)
  772. //
  773. // oprninfo := make([]map[string]interface{},0) // 手术操作信息
  774. // oprninfotemp := make(map[string]interface{})
  775. // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填
  776. // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  777. // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  778. // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填
  779. // oprninfotemp["anst_way"] = "" // 麻醉方式 必填
  780. // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填
  781. // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填
  782. // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填
  783. // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填
  784. // oprninfo = append(oprninfo,iteminfotemp)
  785. //
  786. // icuinfo := make([]map[string]interface{},0) // 重症监护信息
  787. // icuinfotemp := make(map[string]interface{})
  788. // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填
  789. // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填
  790. // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填
  791. // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填
  792. // icuinfo = append(icuinfo,iteminfotemp)
  793. //
  794. //
  795. //
  796. //
  797. // input["setlinfo"] = inputData
  798. // input["payinfo"] = payinfo
  799. // input["opspdiseinfo"] = opspdiseinfo
  800. // input["diseinfo"] = diseinfo
  801. // input["iteminfo"] = iteminfo
  802. // input["oprninfo"] = oprninfo
  803. // input["icuinfo"] = icuinfo
  804. // inputMessage["input"] = input //交易输入
  805. //
  806. // bytesData, err := json.Marshal(inputMessage)
  807. // fmt.Println(string(bytesData))
  808. // if err != nil {
  809. // fmt.Println(err.Error())
  810. // return err.Error()
  811. // }
  812. // reader := bytes.NewReader(bytesData)
  813. //
  814. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  815. // request, err := http.NewRequest("POST", url, reader)
  816. // if err != nil {
  817. // fmt.Println(err.Error())
  818. // return err.Error()
  819. // }
  820. //
  821. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  822. // request.Header.Set("x-tif-paasid", "test_hosp")
  823. // request.Header.Set("x-tif-signature", signature)
  824. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  825. // request.Header.Set("x-tif-nonce", nonce)
  826. //
  827. // client := http.Client{}
  828. // resp, err := client.Do(request)
  829. // if err != nil {
  830. // fmt.Println(err.Error())
  831. // return err.Error()
  832. // }
  833. // respBytes, err := ioutil.ReadAll(resp.Body)
  834. // if err != nil {
  835. // fmt.Println(err.Error())
  836. // return err.Error()
  837. // }
  838. // str := string(respBytes)
  839. // fmt.Println(str)
  840. // return str
  841. //}
  842. // 生成签名
  843. func setSignature(timestamp int64, nonce string, secret_key string) string {
  844. str := strconv.FormatInt(timestamp, 10) + secret_key + nonce + strconv.FormatInt(timestamp, 10)
  845. hash := sha256.New()
  846. //输入数据
  847. hash.Write([]byte(str))
  848. //计算哈希值
  849. bytes := hash.Sum(nil)
  850. //将字符串编码为16进制格式,返回字符串
  851. hashCode := hex.EncodeToString(bytes)
  852. //返回哈希值
  853. return hashCode
  854. }
  855. // 生成随机字符串
  856. func GetRandomString(l int) string {
  857. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  858. bytes := []byte(str)
  859. result := []byte{}
  860. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  861. for i := 0; i < l; i++ {
  862. result = append(result, bytes[r.Intn(len(bytes))])
  863. }
  864. return string(result)
  865. }
  866. // 生成基础报文
  867. func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) map[string]interface{} {
  868. // 生成签名
  869. tempTime := time.Unix(timestamp, 0)
  870. timeFormat := tempTime.Format("20060102150405")
  871. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  872. randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  873. // 生成输入报文
  874. inputMessage := make(map[string]interface{})
  875. inputMessage["infno"] = "1101" // 交易编码
  876. inputMessage["msgid"] = fixmedins_code + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID
  877. inputMessage["mdtrtarea_admvs"] = mdtrtarea_admvs // 就医地医保区划
  878. inputMessage["insuplc_admdvs"] = insuplc_admdvs // 参保地医保区划
  879. inputMessage["recer_sys_code"] = "01" // 接收方系统代码
  880. inputMessage["dev_no"] = "" // 设备编号
  881. inputMessage["dev_safe_info"] = "" // 设备安全信息
  882. inputMessage["cainfo"] = "" // 数字签名信息
  883. inputMessage["signtype"] = "" // 签名类型
  884. inputMessage["infver"] = "V1.1" // 接收方系统代码
  885. inputMessage["opter_type"] = "1" // 经办人类别
  886. inputMessage["opter"] = doctor // 经办人
  887. inputMessage["opter_name"] = doctor // 经办人姓名
  888. inputMessage["inf_time"] = timeFormatOne // 交易时间
  889. inputMessage["fixmedins_code"] = fixmedins_code // 定点医药机构编号
  890. inputMessage["fixmedins_name"] = org_name //定点医药机构名称
  891. inputMessage["sign_no"] = "" //交易签到流水号
  892. return inputMessage
  893. }
  894. //func Gdyb1201(psnNo string, org_name string, doctor string) string {
  895. // // 生成签名
  896. // nonce := GetRandomString(32)
  897. // timestamp := time.Now().Unix()
  898. // signature := setSignature(timestamp, nonce)
  899. //
  900. // // 生成输入报文
  901. // inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  902. // input := make(map[string]interface{})
  903. // inputData := make(map[string]interface{})
  904. // inputMessage["infno"] = "1201" // 交易编码
  905. // inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回)
  906. // inputData["fixmedins_name"] = org_name // 人员编号 (来自1101接口返回)
  907. // inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回)
  908. //
  909. // input["medinsinfo"] = inputData
  910. // inputMessage["input"] = input //交易输入
  911. //
  912. // bytesData, err := json.Marshal(inputMessage)
  913. // fmt.Println(string(bytesData))
  914. // if err != nil {
  915. // fmt.Println(err.Error())
  916. // return err.Error()
  917. // }
  918. // reader := bytes.NewReader(bytesData)
  919. //
  920. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201"
  921. // request, err := http.NewRequest("POST", url, reader)
  922. // if err != nil {
  923. // fmt.Println(err.Error())
  924. // return err.Error()
  925. // }
  926. //
  927. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  928. // request.Header.Set("x-tif-paasid", "test_hosp")
  929. // request.Header.Set("x-tif-signature", signature)
  930. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  931. // request.Header.Set("x-tif-nonce", nonce)
  932. //
  933. // client := http.Client{}
  934. // resp, err := client.Do(request)
  935. // if err != nil {
  936. // fmt.Println(err.Error())
  937. // return err.Error()
  938. // }
  939. // respBytes, err := ioutil.ReadAll(resp.Body)
  940. // if err != nil {
  941. // fmt.Println(err.Error())
  942. // return err.Error()
  943. // }
  944. // str := string(respBytes)
  945. // fmt.Println(str)
  946. // return str
  947. //}