package service import ( "XT_New/models" //"/models" "bytes" "crypto/sha256" "encoding/hex" "encoding/json" "fmt" "io" "io/ioutil" "math/rand" "mime/multipart" "net/http" "os" "path/filepath" "strconv" "strings" "time" _ "unsafe" ) const ( SceretKey = "RhaDw4H0RUbWYyTxmRKM1eSeN0qyGLds" // secretKey 私钥 ) // 人员基本信息 func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "1101" // 交易编码 inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型 inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号 inputData["card_sn"] = "" // 卡识别码 inputData["begntime"] = "" // 开始时间 inputData["psn_cert_type"] = "1" // 人员证件类型 inputData["certno"] = certNo // 证件号码 inputData["psn_name"] = "" // 人员姓名 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } fmt.Println(string(respBytes)) str := string(respBytes) return str } // 门诊挂号 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 { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) tempTime := time.Unix(timestamp, 0) timeFormatOne := tempTime.Format("2006-01-02 15:04:05") // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "2201" // 交易编码 inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["insutype"] = insutype // 险种类型(来自1101接口返回) inputData["begntime"] = timeFormatOne // 开始时间 inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型 inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号 inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号 inputData["atddr_no"] = doctor_id // 医师编码 inputData["dr_name"] = doctor // 医师姓名 inputData["dept_code"] = dept_code // 科室编码 inputData["dept_name"] = dept // 科室名称 inputData["caty"] = "A03.06" // 科别 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2201" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2201" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } func Gdyb2201ForGzyb(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, psn_name string) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) tempTime := time.Unix(timestamp, 0) timeFormatOne := tempTime.Format("2006-01-02 15:04:05") // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputData2 := make(map[string]interface{}) inputMessage["infno"] = "2201" // 交易编码 inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["insutype"] = insutype // 险种类型(来自1101接口返回) inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型 inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号 inputData["hcard_basinfo"] = "" // 就诊凭证编号 inputData["hcard_chkinfo"] = "" // 就诊凭证编号 inputData["begntime"] = timeFormatOne // 开始时间 inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号 inputData["dept_code"] = dept_code // 科室编码 inputData["dept_name"] = dept // 科室名称 inputData["atddr_no"] = doctor_id // 医师编码 inputData["dr_name"] = doctor // 医师姓名 inputData["caty"] = "A03.06" // 科别 input["mdtrtinfo"] = inputData inputData2["agnter_name"] = psn_name inputData2["gnter_rlts"] = "01" inputData2["agnter_cert_type"] = "01" inputData2["agnter_certno"] = certNo inputData2["agnter_tel"] = "13535547901" inputData2["agnter_addr"] = "xxxxxx" inputData2["agnter_photo"] = "xxxxxxx" input["agnterinfo"] = inputData2 inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2201" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 门诊挂号撤销 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 { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "2202" // 交易编码 inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2202" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") //request.Header.Set("x-tif-paasid", "test_hosp") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 门诊就诊信息上传 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 { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) tempTime := time.Unix(timestamp, 0) timeFormatOne := tempTime.Format("2006-01-02 15:04:05") // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) diseinfo := make([]map[string]interface{}, 0) inputMessage["infno"] = "2203" // 交易编码 inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["med_type"] = med_type // 医疗类别 16门诊特殊病 inputData["begntime"] = timeFormatOne // 开始时间 inputData["main_cond_dscr"] = "" // 主要病情描述 inputData["dise_codg"] = "" // 病种编码 inputData["dise_name"] = "" // 病种名称 inputData["birctrl_type"] = "" // 计划生育手术类别 inputData["birctrl_matn_date"] = "" // 计划生育手术或生育日期 diseinfo_sun := make(map[string]interface{}) diseinfo_sun["diag_type"] = "1" // 诊断类别 diseinfo_sun["diag_srt_no"] = "1" // 诊断排序号 diseinfo_sun["diag_code"] = diag_code // 诊断代码 diseinfo_sun["diag_name"] = diag // 诊断名称 diseinfo_sun["diag_dept"] = department // 诊断科室 diseinfo_sun["dise_dor_no"] = doctor_id // 诊断医生编码 diseinfo_sun["dise_dor_name"] = doctor // 诊断医生姓名 diseinfo_sun["diag_time"] = timeFormatOne // 诊断时间 diseinfo_sun["vali_flag"] = "1" // 有效标志 diseinfo = append(diseinfo, diseinfo_sun) input["diseinfo"] = diseinfo input["mdtrtinfo"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2203" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2203" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } type Custom struct { DetItemFeeSumamt string Cut string FeedetlSn string Price string MedListCodg string } type RequestResult struct { Output Output `json:"output" form:"output"` Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"` WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"` Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"` ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"` RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"` InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"` } type Output struct { Result Result `json:"result" form:"result"` } type Result struct { BasMednFlag string `json:"bas_medn_flag" form:"bas_medn_flag"` MedChrgitmType string `json:"med_chrgitm_type" form:"med_chrgitm_type"` DetItemFeeSumamt int64 `json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"` HiNegoDrugFlag string `json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"` FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"` FeedtlSn int64 `json:"feedtl_sn" form:"feedtl_sn"` UploadDate int64 `json:"upload_date" form:"upload_date"` AdviceId int64 `json:"advice_id" form:"advice_id"` Cnt int64 `json:"cnt" form:"cnt"` Pric float64 `json:"pric" form:"pric"` PatientId int64 `json:"patient_id" form:"patient_id"` PricUplmtAmt float64 `json:"pric_uplmt_amt" form:"pric_uplmt_amt"` SelfpayProp float64 `json:"selfpay_prop" form:"selfpay_prop"` OverlmtAmt float64 `json:"overlmt_amt" form:"overlmt_amt"` PreselfpayAmt float64 `json:"preselfpay_amt" form:"preselfpay_amt"` Status int64 `json:"status" form:"status"` Memo string `json:"memo" form:"memo"` FeedetlSn string `json:"feedetl_sn" form:"feedetl_sn"` Mtime int64 `json:"mtime" form:"mtime"` InscpScpAmt float64 `json:"inscp_scp_amt" form:"inscp_scp_amt"` DrtReimFlag string `json:"drt_reim_flag" form:"drt_reim_flag"` Ctime int64 `json:"ctime" form:"ctime"` ListSpItemFlag string `json:"list_sp_item_flag" form:"list_sp_item_flag"` ChldMedcFlag string `json:"chld_medc_flag" form:"chld_medc_flag"` LmtUsedFlag string `json:"lmt_used_flag" form:"lmt_used_flag"` ChrgitmLv string `json:"chrgitm_lv" form:"chrgitm_lv"` UserOrgId int64 `json:"user_org_id" form:"user_org_id"` HisPatientId int64 `json:"his_patient_id" form:"his_patient_id"` OrderId int64 `json:"order_id" form:"order_id"` } // 门诊费用明细信息上传 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 { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) tempTime := time.Unix(timestamp, 0) //timeFormat := tempTime.Format("20060102150405") timeFormatOne := tempTime.Format("2006-01-02 15:04:05") //chrgBchno := rand.Intn(100000) + 10000 var customs []*Custom for _, item := range hisPrescription { if item.Type == 1 { //药品 for _, subItem := range item.HisDoctorAdviceInfo { if len(subItem.MedListCodg) > 0 { //var randNum int //randNum = rand.Intn(10000) + 1000 cus := &Custom{ DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", subItem.Price), MedListCodg: subItem.MedListCodg, } customs = append(customs, cus) } } } if item.Type == 2 { //项目 for _, subItem := range item.HisPrescriptionProject { //var randNum int //randNum = rand.Intn(10000) + 1000 if len(subItem.MedListCodg) > 0 { cut, _ := strconv.ParseFloat(subItem.Count, 64) cus := &Custom{ DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cut), Cut: fmt.Sprintf("%.2f", cut), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(subItem.Price)), MedListCodg: subItem.MedListCodg, } customs = append(customs, cus) } } } for _, subItem := range item.HisAdditionalCharge { if len(subItem.XtHisAddtionConfig.Code) > 0 { cus := &Custom{ DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), Cut: fmt.Sprintf("%.2f", float64(subItem.Count)), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(subItem.Price)), MedListCodg: subItem.XtHisAddtionConfig.Code, } customs = append(customs, cus) } } } // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) feedetail := make([]map[string]interface{}, 0) inputMessage["infno"] = "2204" // 交易编码 //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) for _, item := range customs { feedetailInfo := make(map[string]interface{}) feedetailInfo["feedetl_sn"] = item.FeedetlSn feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回) feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号 feedetailInfo["dise_codg"] = "" // 病种编码 feedetailInfo["rxno"] = "" // 处方号 feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志 feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间 feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码 feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码 feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额 feedetailInfo["cnt"] = item.Cut // 数量 feedetailInfo["pric"] = item.Price // 单价 feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述 feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述 feedetailInfo["prd_days"] = "0" // 周期天数 feedetailInfo["medc_way_dscr"] = "" // 用药途径描述 feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码 feedetailInfo["bilg_dept_name"] = dept // 开单科室名称 feedetailInfo["bilg_dr_codg"] = doctor_id // 开单医生编码 feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名 feedetailInfo["acord_dept_codg"] = "" // 受单科室编码 feedetailInfo["acord_dept_name"] = "" // 受单科室名称 feedetailInfo["orders_dr_code"] = "" // 受单医生编码 feedetailInfo["orders_dr_name"] = "" // 受单医生姓名 feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志 feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式 feedetailInfo["etip_flag"] = "" // 外检标志 feedetailInfo["etip_hosp_code"] = "" // 外检医院编码 feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志 feedetailInfo["matn_fee_flag"] = "" // 生育费用标志 feedetail = append(feedetail, feedetailInfo) } input["feedetail"] = feedetail inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println("----------") fmt.Println(string(bytesData)) fmt.Println("----------") if err != nil { fmt.Println(err.Error()) return "" } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2204" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return "" } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return "" } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return "" } return string(respBytes) //var result RequestResult //json.Unmarshal(respBytes, &result) //return &result } // 门诊费用明细信息撤销 func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "2205" // 交易编码 inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的) inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2205" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205" request, err := http.NewRequest("POST", url, reader) fmt.Println(err) fmt.Println(request) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 门诊预结算 func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, secret_key string) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", "", "") input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "2206" // 交易编码 inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型, inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号 inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号 inputData["medfee_sumamt"] = total // 医疗费总额 inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算 inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的) inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是 inputData["insutype"] = insutype // 险种类型 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2206" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 门诊结算 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 { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "2207" // 交易编码 inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型 inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号 inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号 inputData["medfee_sumamt"] = total // 医疗费总额 inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算 inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的) inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是 inputData["insutype"] = insutype // 险种类型 inputData["invono"] = "" // 发票号 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 门诊结算撤销 func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, secret_key) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "2208" // 交易编码 inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回) inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回) inputData["setl_id"] = setlId // 结算 ID input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2208" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 医药机构费用结算对总账 func Gdyb3201( org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string { func Gdyb3201(baseParams models.BaseParams, businessParams models.BusinessParams) string { fmt.Println("11222333-----") fmt.Println(baseParams) fmt.Println(businessParams) // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, baseParams.SecretKey) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "3201" // 交易编码 inputData["insutype"] = businessParams.Insutype // 险种 inputData["clr_type"] = businessParams.ClrType // 就诊 ID(来自2201接口返回) inputData["setl_optins"] = baseParams.OrgName // 结算经办机构 inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间 inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间 inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额 inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额 inputData["acct_pay"] = businessParams.AcctPay //个人账户支付金额 inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3201" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3201" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } type Params struct { FileName string `json:"file_name"` //产品ID In []byte `json:"in"` // FixmedinsCode string `json:"fixmedins_code"` //调用环境生产为1 沙盒2 } // 文件上传 // 文件上传 func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, baseParams.SecretKey) buf := new(bytes.Buffer) buf.ReadFrom(strings.NewReader(string(file_byte))) inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "9101" // 交易编码 inputData["file_name"] = file_name //文件名 inputData["in"] = bytes.NewBuffer(file_byte).Bytes() //文件数据 inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码 input["fsUploadIn"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9101" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9101" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } func Gdyb9102(baseParams models.BaseParams, file_name string, file_qury_no string) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, baseParams.SecretKey) inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "9102" // 交易编码 inputData["file_name"] = file_name //文件名 inputData["file_qury_no"] = "fsi/H44022900158/" + file_qury_no //文件数据 inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码 input["fsDownloadIn"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9102" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9102" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } func Gdyb3202(baseParams models.BaseParams, businessParams models.BusinessParams) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, baseParams.SecretKey) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "3202" // 交易编码 inputData["file_qury_no"] = "fsi/H44022900158/" + businessParams.FileQuryNo // 险种 inputData["setl_optins"] = baseParams.OrgName // 结算经办机构 inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间 inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间 inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额 inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额 inputData["cash_payamt"] = businessParams.CashPayamt //现金支付金额 inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数 input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3202" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3202" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } func Gdyb5203(baseParams models.BaseParams, businessParams models.BusinessParams) string { // 生成签名 nonce := GetRandomString(32) timestamp := time.Now().Unix() signature := setSignature(timestamp, nonce, baseParams.SecretKey) // 生成输入报文 inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs) input := make(map[string]interface{}) inputData := make(map[string]interface{}) inputMessage["infno"] = "5203" // 交易编码 inputData["psn_no"] = businessParams.PsnNo inputData["setl_id"] = businessParams.SetlId inputData["mdtrt_id"] = businessParams.MdtrtId input["data"] = inputData inputMessage["input"] = input //交易输入 bytesData, err := json.Marshal(inputMessage) fmt.Println(string(bytesData)) if err != nil { fmt.Println(err.Error()) return err.Error() } reader := bytes.NewReader(bytesData) url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/5203" //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/5203" request, err := http.NewRequest("POST", url, reader) if err != nil { fmt.Println(err.Error()) return err.Error() } request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("x-tif-paasid", "sg03_prd") request.Header.Set("x-tif-signature", signature) request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) request.Header.Set("x-tif-nonce", nonce) client := http.Client{} resp, err := client.Do(request) if err != nil { fmt.Println(err.Error()) return err.Error() } respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err.Error()) return err.Error() } str := string(respBytes) fmt.Println(str) return str } // 门诊结算撤销 //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string { // // 生成签名 // nonce := GetRandomString(32) // timestamp := time.Now().Unix() // signature := setSignature(timestamp, nonce) // // // 生成输入报文 // inputMessage := SetInputMessage(nonce, timestamp) // input := make(map[string]interface{}) // inputData := make(map[string]interface{}) // inputMessage["infno"] = "4101" // 交易编码 // // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回) // inputData["setl_id"] = setlId // 结算 ID 必填 // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填 // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填 // inputData["hi_setl_lv"] = "" // 医保结算等级 // inputData["hi_no"] = "" // 医保编号 // inputData["medcasno"] = "" // 病案号 必填 // inputData["dcla_time"] = "" // 申报时间 必填 // inputData["psn_name"] = "" // 人员姓名 必填 // inputData["gend"] = "" // 性别 必填 // inputData["brdy"] = "" // 出生日期 必填 // inputData["age"] = "" // 年龄 必填 // inputData["ntly"] = "" // 国籍 必填 // inputData["nwb_age"] = "" // 年龄 必填 // inputData["naty"] = "" // 民族 必填 // inputData["patn_cert_type"] = "" // 患者证件类别 必填 // inputData["certno"] = "" // 证件号码 必填 // inputData["prfs"] = "" // 职业 必填 // inputData["curr_addr"] = "" // 现住址 必填 // inputData["emp_name"] = "" // 单位名称 必填 // inputData["emp_addr"] = "" // 单位地址 必填 // inputData["emp_tel"] = "" // 单位电话 必填 // inputData["poscode"] = "" // 邮编 必填 // inputData["coner_name"] = "" // 联系人姓名 必填 // inputData["patn_rlts"] = "" // 与患者关系 必填 // inputData["coner_addr"] = "" // 联系人地址 必填 // inputData["coner_tel"] = "" // 联系人电话 必填 // inputData["hi_type"] = "" // 医保类型 必填 // inputData["insuplc"] = "" // 参保地 必填 // inputData["sp_psn_type"] = "" // 特殊人员类型 必填 // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填 // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填 // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填 // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填 // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填 // inputData["ipt_med_type"] = "" // 住院医疗类型 必填 // inputData["adm_way"] = "" // 入院途径 必填 // inputData["trt_type"] = "" // 治疗类别 必填 // inputData["adm_time"] = "" // 入院时间 必填 // inputData["adm_caty"] = "" // 入院科别 必填 // inputData["refldept_dept"] = "" // 转科科别 必填 // inputData["dscg_time"] = "" // 出院时间 必填 // inputData["dscg_caty"] = "" // 出院科别 必填 // inputData["act_ipt_days"] = "" // 实际住院天数 必填 // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填 // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填 // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填 // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填 // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填 // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填 // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填 // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填 // inputData["bld_cat"] = "" // 输血品种 必填 // inputData["bld_amt"] = "" // 输血量 必填 // inputData["bld_unt"] = "" // 输血计量单位 必填 // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填 // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填 // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填 // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填 // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填 // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填 // inputData["bill_code"] = "" // 票据代码 必填 // inputData["bill_no"] = "" // 票据号码 必填 // inputData["biz_sn"] = "" // 业务流水号 必填 // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填 // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填 // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填 // inputData["chfpdr_code"] = "" // 主诊医师代码 必填 // inputData["setl_begn_date"] = "" // 结算开始日期 必填 // inputData["setl_end_date"] = "" // 结算结束日期 必填 // inputData["psn_selfpay"] = "" // 个人自付 必填 // inputData["psn_ownpay"] = "" // 个人自费 必填 // inputData["acct_pay"] = "" // 个人账户支出 必填 // inputData["hi_paymtd"] = "" // 医保支付方式 必填 // inputData["hsorg"] = "" // 医保机构 必填 // inputData["hsorg_opter"] = "" // 医保机构经办人 必填 // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填 // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填 // // payinfo := make([]map[string]interface{},0) // 基金支付信息 // payinfotemp := make(map[string]interface{}) // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填 // payinfotemp["fund_payamt"] = "" // 基金支付金额 // payinfo = append(payinfo,payinfotemp) // // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息 // opspdiseinfotemp := make(map[string]interface{}) // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填 // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填 // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填 // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填 // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp) // // diseinfo := make([]map[string]interface{},0) // 住院诊断信息 // diseinfotemp := make(map[string]interface{}) // diseinfotemp["diag_type"] = "" // 诊断类别 必填 // diseinfotemp["diag_code"] = "" // 诊断代码 必填 // diseinfotemp["diag_name"] = "" // 诊断名称 必填 // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填 // diseinfo = append(diseinfo,diseinfotemp) // // iteminfo := make([]map[string]interface{},0) // 住院诊断信息 // iteminfotemp := make(map[string]interface{}) // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填 // iteminfotemp["amt"] = "" // 金额 必填 // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填 // iteminfotemp["clab_amt"] = "" // 乙类金额 必填 // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填 // iteminfotemp["oth_amt"] = "" // 其他金额 必填 // iteminfo = append(iteminfo,iteminfotemp) // // oprninfo := make([]map[string]interface{},0) // 手术操作信息 // oprninfotemp := make(map[string]interface{}) // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填 // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填 // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填 // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填 // oprninfotemp["anst_way"] = "" // 麻醉方式 必填 // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填 // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填 // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填 // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填 // oprninfo = append(oprninfo,iteminfotemp) // // icuinfo := make([]map[string]interface{},0) // 重症监护信息 // icuinfotemp := make(map[string]interface{}) // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填 // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填 // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填 // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填 // icuinfo = append(icuinfo,iteminfotemp) // // // // // input["setlinfo"] = inputData // input["payinfo"] = payinfo // input["opspdiseinfo"] = opspdiseinfo // input["diseinfo"] = diseinfo // input["iteminfo"] = iteminfo // input["oprninfo"] = oprninfo // input["icuinfo"] = icuinfo // inputMessage["input"] = input //交易输入 // // bytesData, err := json.Marshal(inputMessage) // fmt.Println(string(bytesData)) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // reader := bytes.NewReader(bytesData) // // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208" // request, err := http.NewRequest("POST", url, reader) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // // request.Header.Set("Content-Type", "application/json;charset=UTF-8") // request.Header.Set("x-tif-paasid", "test_hosp") // request.Header.Set("x-tif-signature", signature) // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) // request.Header.Set("x-tif-nonce", nonce) // // client := http.Client{} // resp, err := client.Do(request) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // respBytes, err := ioutil.ReadAll(resp.Body) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // str := string(respBytes) // fmt.Println(str) // return str //} // 生成签名 func setSignature(timestamp int64, nonce string, secret_key string) string { str := strconv.FormatInt(timestamp, 10) + secret_key + nonce + strconv.FormatInt(timestamp, 10) hash := sha256.New() //输入数据 hash.Write([]byte(str)) //计算哈希值 bytes := hash.Sum(nil) //将字符串编码为16进制格式,返回字符串 hashCode := hex.EncodeToString(bytes) //返回哈希值 return hashCode } // 生成随机字符串 func GetRandomString(l int) string { str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" bytes := []byte(str) result := []byte{} r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < l; i++ { result = append(result, bytes[r.Intn(len(bytes))]) } return string(result) } // 生成基础报文 func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) map[string]interface{} { // 生成签名 tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") timeFormatOne := tempTime.Format("2006-01-02 15:04:05") randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000) // 生成输入报文 inputMessage := make(map[string]interface{}) inputMessage["infno"] = "1101" // 交易编码 inputMessage["msgid"] = fixmedins_code + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID inputMessage["mdtrtarea_admvs"] = mdtrtarea_admvs // 就医地医保区划 inputMessage["insuplc_admdvs"] = insuplc_admdvs // 参保地医保区划 inputMessage["recer_sys_code"] = "01" // 接收方系统代码 inputMessage["dev_no"] = "" // 设备编号 inputMessage["dev_safe_info"] = "" // 设备安全信息 inputMessage["cainfo"] = "" // 数字签名信息 inputMessage["signtype"] = "" // 签名类型 inputMessage["infver"] = "V1.1" // 接收方系统代码 inputMessage["opter_type"] = "1" // 经办人类别 inputMessage["opter"] = doctor // 经办人 inputMessage["opter_name"] = doctor // 经办人姓名 inputMessage["inf_time"] = timeFormatOne // 交易时间 inputMessage["fixmedins_code"] = fixmedins_code // 定点医药机构编号 inputMessage["fixmedins_name"] = org_name //定点医药机构名称 inputMessage["sign_no"] = "" //交易签到流水号 return inputMessage } func postFile(filename string, target_url string) (*http.Response, error) { body_buf := bytes.NewBufferString("") body_writer := multipart.NewWriter(body_buf) // use the body_writer to write the Part headers to the buffer _, err := body_writer.CreateFormFile("userfile", filename) if err != nil { fmt.Println("error writing to buffer") return nil, err } // the file data will be the second part of the body fh, err := os.Open(filename) if err != nil { fmt.Println("error opening file") return nil, err } // need to know the boundary to properly close the part myself. boundary := body_writer.Boundary() //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary) close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary)) // use multi-reader to defer the reading of the file data until // writing to the socket buffer. request_reader := io.MultiReader(body_buf, fh, close_buf) fi, err := fh.Stat() if err != nil { fmt.Printf("Error Stating file: %s", filename) return nil, err } req, err := http.NewRequest("POST", target_url, request_reader) if err != nil { return nil, err } // Set headers for multipart, and Content Length req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundary) req.ContentLength = fi.Size() + int64(body_buf.Len()) + int64(close_buf.Len()) return http.DefaultClient.Do(req) } //func Gdyb1201(psnNo string, org_name string, doctor string) string { // // 生成签名 // nonce := GetRandomString(32) // timestamp := time.Now().Unix() // signature := setSignature(timestamp, nonce) // // // 生成输入报文 // inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "") // input := make(map[string]interface{}) // inputData := make(map[string]interface{}) // inputMessage["infno"] = "1201" // 交易编码 // inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回) // inputData["fixmedins_name"] = org_name // 人员编号 (来自1101接口返回) // inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回) // // input["medinsinfo"] = inputData // inputMessage["input"] = input //交易输入 // // bytesData, err := json.Marshal(inputMessage) // fmt.Println(string(bytesData)) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // reader := bytes.NewReader(bytesData) // // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201" // request, err := http.NewRequest("POST", url, reader) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // // request.Header.Set("Content-Type", "application/json;charset=UTF-8") // request.Header.Set("x-tif-paasid", "test_hosp") // request.Header.Set("x-tif-signature", signature) // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10)) // request.Header.Set("x-tif-nonce", nonce) // // client := http.Client{} // resp, err := client.Do(request) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // respBytes, err := ioutil.ReadAll(resp.Body) // if err != nil { // fmt.Println(err.Error()) // return err.Error() // } // str := string(respBytes) // fmt.Println(str) // return str //} func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) { file, err := os.Open(path) if err != nil { return nil, err } defer file.Close() body := &bytes.Buffer{} writer := multipart.NewWriter(body) part, err := writer.CreateFormFile(paramName, filepath.Base(path)) if err != nil { return nil, err } _, err = io.Copy(part, file) for key, val := range params { _ = writer.WriteField(key, val) } err = writer.Close() if err != nil { return nil, err } req, err := http.NewRequest("POST", uri, body) req.Header.Set("Content-Type", writer.FormDataContentType()) return req, err }