gxyb_service.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. package service
  2. import (
  3. //"crypto/md5"
  4. //"strings"
  5. //"gdyb/utils"
  6. "time"
  7. "fmt"
  8. "encoding/json"
  9. "github.com/astaxie/beego"
  10. "net/http"
  11. "strconv"
  12. "io/ioutil"
  13. "bytes"
  14. "github.com/go-ole/go-ole"
  15. "github.com/go-ole/go-ole/oleutil"
  16. )
  17. func Gxyb9001(org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, admin_user_id int64,setlId string,mdtrtId string,psn_no string,medinsSetlId string){
  18. ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
  19. defer ole.CoUninitialize()
  20. // Replace with the ProgID or CLSID of your COM object
  21. progID := "YinHai.XJ.Actual.Interface.New"
  22. // Create COM object
  23. unknown, err := oleutil.CreateObject(progID)
  24. if err != nil {
  25. fmt.Println("Unable to create COM object:", err)
  26. }
  27. defer unknown.Release()
  28. // Query for the IDispatch interface
  29. dispatch, err := unknown.QueryInterface(ole.IID_IDispatch)
  30. if err != nil {
  31. fmt.Println("Unable to get IDispatch interface:", err)
  32. }
  33. defer dispatch.Release()
  34. nonce := GetRandomString(32)
  35. timestamp := time.Now().Unix()
  36. inputMessage := make(map[string]interface{})
  37. inputMessage = SetInputMessage1111(nonce, timestamp, org_name, admin_user_id, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs,doctor)
  38. input := make(map[string]interface{})
  39. inputData := make(map[string]interface{})
  40. inputMessage["infno"] = "P0001" // 交易编码
  41. inputData["setlId"] = setlId
  42. inputData["mdtrtId"] = mdtrtId
  43. inputData["psn_no"] = psn_no
  44. inputData["medinsSetlId"] = medinsSetlId
  45. input["data"] = inputData
  46. inputMessage["input"] = input //交易输入
  47. jsonData, err := json.Marshal(inputMessage)
  48. if err != nil {
  49. fmt.Println("转换为JSON失败:", err)
  50. }
  51. //data := fmt.Sprintf(`{"transNo":"%s","transType":"%s","timestamp":"%s","data":{"fixmedinsCode":"%s","psnNo":"%s"}}`, transNo, transType, timestamp, fixmedinsCode, psnNo)
  52. result2 := ""
  53. // Call COM object's method using the IDispatch interface
  54. resulr, err := oleutil.CallMethod(dispatch, "gxyb_call", "P0001", string(jsonData),&result2)
  55. fmt.Println(resulr)
  56. }
  57. func Gxyb5302(psnNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string,admin_user_id int64) string {
  58. // 生成签名
  59. nonce := GetRandomString(32)
  60. //timestamp := time.Now().Unix()
  61. timestamp := time.Now().UnixNano() / 1e6
  62. signature := setSignature(timestamp, nonce, secret_key)
  63. inputMessage := SetInputMessage1111(nonce, timestamp, org_name, admin_user_id, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs,doctor)
  64. // 生成输入报文
  65. //inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  66. input := make(map[string]interface{})
  67. inputData := make(map[string]interface{})
  68. inputMessage["infno"] = "5302" // 交易编码
  69. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  70. inputData["biz_appy_type"] = "03" // 人员编号 (来自1101接口返回)
  71. input["data"] = inputData
  72. inputMessage["input"] = input //交易输入
  73. bytesData, err := json.Marshal(inputMessage)
  74. fmt.Println(string(bytesData))
  75. if err != nil {
  76. fmt.Println(err.Error())
  77. return err.Error()
  78. }
  79. reader := bytes.NewReader(bytesData)
  80. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/5301"
  81. gdyb_url := beego.AppConfig.String("gdyb_url")
  82. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  83. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  84. url := gdyb_url
  85. request, err := http.NewRequest("POST", url, reader)
  86. if err != nil {
  87. fmt.Println(err.Error())
  88. return err.Error()
  89. }
  90. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  91. request.Header.Set("x-tif-paasid", gdyb_paasid)
  92. request.Header.Set("x-tif-signature", signature)
  93. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  94. request.Header.Set("x-tif-nonce", nonce)
  95. client := http.Client{}
  96. resp, err := client.Do(request)
  97. if err != nil {
  98. fmt.Println(err.Error())
  99. return err.Error()
  100. }
  101. respBytes, err := ioutil.ReadAll(resp.Body)
  102. if err != nil {
  103. fmt.Println(err.Error())
  104. return err.Error()
  105. }
  106. str := string(respBytes)
  107. fmt.Println(str)
  108. return str
  109. }
  110. func Gxyb2207(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, med_type string, id_card_type int64, fulamt_ownpay_amt float64, overlmt_selfpay float64, preselfpay_amt float64, inscp_scp_amt float64, certificates int64, acct_used_flag string, token string,admin_user_id int64) (string, string) {
  111. // 生成签名
  112. nonce := GetRandomString(32)
  113. timestamp := time.Now().Unix()
  114. signature := setSignature(timestamp, nonce, secret_key)
  115. // 生成输入报文
  116. inputMessage := make(map[string]interface{})
  117. if mdtrtarea_admvs == "450721" || mdtrtarea_admvs == "450127"{
  118. inputMessage = SetInputMessage1111(nonce, timestamp, org_name, admin_user_id, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs,doctor)
  119. } else {
  120. inputMessage = SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  121. }
  122. //inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  123. input := make(map[string]interface{})
  124. inputData := make(map[string]interface{})
  125. inputMessage["infno"] = "2207" // 交易编码
  126. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  127. if certificates == 3 {
  128. inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
  129. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  130. } else {
  131. if id_card_type == 1 {
  132. inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
  133. inputData["mdtrt_cert_no"] = token // 就诊凭证编号
  134. } else if id_card_type == 4 {
  135. inputData["mdtrt_cert_type"] = "01" // 就诊凭证类型
  136. inputData["mdtrt_cert_no"] = token // 就诊凭证编号
  137. } else {
  138. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  139. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  140. }
  141. }
  142. if med_type == "1111" || med_type == "1112" {
  143. med_type = "11"
  144. }
  145. if insuplc_admdvs == "421300" {
  146. if med_type == "11" {
  147. inputData["med_type"] = "110104" // 医疗类别 11 普通门诊 12 门诊挂号
  148. } else if med_type == "14" {
  149. inputData["med_type"] = "140101" // 医疗类别 11 普通门诊 12 门诊挂号
  150. }
  151. } else {
  152. inputData["med_type"] = med_type // 医疗类别 11 普通门诊 12 门诊挂号
  153. }
  154. inputData["medfee_sumamt"] = total // 医疗费总额
  155. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  156. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  157. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  158. inputData["acct_used_flag"] = acct_used_flag // 个人账户使用标志 0否 1是
  159. inputData["insutype"] = insutype // 险种类型
  160. inputData["invono"] = "" // 发票号
  161. inputData["fulamt_ownpay_amt"] = fulamt_ownpay_amt //
  162. inputData["overlmt_selfpay"] = overlmt_selfpay //
  163. inputData["preselfpay_amt"] = preselfpay_amt //
  164. inputData["inscp_scp_amt"] = inscp_scp_amt //
  165. input["data"] = inputData
  166. inputMessage["input"] = input //交易输入
  167. bytesData, err := json.Marshal(inputMessage)
  168. fmt.Println(string(bytesData))
  169. if err != nil {
  170. fmt.Println(err.Error())
  171. return err.Error(), ""
  172. }
  173. reader := bytes.NewReader(bytesData)
  174. gdyb_url := beego.AppConfig.String("gdyb_url")
  175. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  176. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  177. //url := gdyb_url + "2207"
  178. var url string
  179. if fixmedins_code == "H15049901371" || mdtrtarea_admvs == "450127" || mdtrtarea_admvs == "450721" {
  180. url = gdyb_url
  181. } else {
  182. url = gdyb_url + "2207"
  183. }
  184. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207"
  185. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  186. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  187. request, err := http.NewRequest("POST", url, reader)
  188. if err != nil {
  189. fmt.Println(err.Error())
  190. return err.Error(), ""
  191. }
  192. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  193. request.Header.Set("x-tif-paasid", gdyb_paasid)
  194. request.Header.Set("x-tif-signature", signature)
  195. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  196. request.Header.Set("x-tif-nonce", nonce)
  197. client := http.Client{}
  198. resp, err := client.Do(request)
  199. if err != nil {
  200. fmt.Println(err.Error())
  201. return err.Error(), ""
  202. }
  203. respBytes, err := ioutil.ReadAll(resp.Body)
  204. if err != nil {
  205. fmt.Println(err.Error())
  206. return err.Error(), ""
  207. }
  208. str := string(respBytes)
  209. fmt.Println(str)
  210. mjson, _ := json.Marshal(inputMessage)
  211. str2 := string(mjson)
  212. return str, str2
  213. }
  214. func Gxyb2503( org_name string, doctor string, fixmedins_code string,insuplc_admdvs string, mdtrtarea_admvs string, secret_key string,admin_user_id int64) string {
  215. // 生成签名
  216. nonce := GetRandomString(32)
  217. timestamp := time.Now().Unix()
  218. signature := setSignature(timestamp, nonce, secret_key)
  219. // 生成输入报文
  220. inputMessage := SetInputMessage1111(nonce, timestamp, org_name, admin_user_id, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs,doctor)
  221. input := make(map[string]interface{})
  222. inputData := make(map[string]interface{})
  223. inputMessage["infno"] = "2503" // 交易编码
  224. inputData["psn_no"] = "45000000000008100150404986" // 人员编号 (来自1101接口返回)
  225. inputData["insutype"] = "390" // 险种类型(来自1101接口返回)
  226. inputData["opsp_dise_code"] = "M03900" // 险种类型(来自1101接口返回)
  227. inputData["opsp_dise_name"] = "高血压(高危组)" // 险种类型(来自1101接口返回)
  228. inputData["insu_optins"] = "450721" // 险种类型(来自1101接口返回)
  229. inputData["ide_fixmedins_no"] = "H45072101171" // 险种类型(来自1101接口返回)
  230. inputData["ide_fixmedins_name"] = "灵山盛康血液透析中心" // 险种类型(来自1101接口返回)
  231. inputData["hosp_ide_date"] = "2024-02-01" // 险种类型(来自1101接口返回)
  232. inputData["diag_dr_codg"] = "D450721000406" // 开始时间
  233. inputData["diag_dr_name"] = "韦秋萍" // 开始时间
  234. inputData["begndate"] = "2024-02-01" // 医师编码
  235. inputData["tel"] = "" // 医师编码
  236. inputData["addr"] = "" // 医师编码
  237. inputData["enddate"] = "2026-01-30" // 医师编码
  238. input["data"] = inputData
  239. inputMessage["input"] = input //交易输入
  240. bytesData, err := json.Marshal(inputMessage)
  241. fmt.Println(string(bytesData))
  242. if err != nil {
  243. fmt.Println(err.Error())
  244. return err.Error()
  245. }
  246. reader := bytes.NewReader(bytesData)
  247. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2503"
  248. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2503"
  249. gdyb_url := beego.AppConfig.String("gdyb_url")
  250. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  251. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  252. //url := gdyb_url + "2503"
  253. var url string
  254. url = gdyb_url
  255. request, err := http.NewRequest("POST", url, reader)
  256. if err != nil {
  257. fmt.Println(err.Error())
  258. return err.Error()
  259. }
  260. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  261. request.Header.Set("x-tif-paasid", gdyb_paasid)
  262. request.Header.Set("x-tif-signature", signature)
  263. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  264. request.Header.Set("x-tif-nonce", nonce)
  265. client := http.Client{}
  266. resp, err := client.Do(request)
  267. if err != nil {
  268. fmt.Println(err.Error())
  269. return err.Error()
  270. }
  271. respBytes, err := ioutil.ReadAll(resp.Body)
  272. if err != nil {
  273. fmt.Println(err.Error())
  274. return err.Error()
  275. }
  276. str := string(respBytes)
  277. fmt.Println(str)
  278. return str
  279. }