package bankapi import ( "dashoo.cn/backend/api/business/paymentinfo" "dashoo.cn/backend/api/models" "encoding/json" "fmt" "io/ioutil" "strconv" "time" "dashoo.cn/backend/api/business/bankapi" // "fmt" . "dashoo.cn/backend/api/controllers" "dashoo.cn/utils" ) // 提供给银行接口的用户名 和 密码:icbc2019, Icbc@2019## // Operations about Users type ICBCController struct { BaseController } // @Title 获取银行支付所需账单信息 // @Description post bills by token // @Success 200 {object} BILLs // @router /bill-list [post] func (this *ICBCController) GetBillList() { var icbcBillQueryParam bankapi.ICBCBillQueryParam json.Unmarshal(this.Ctx.Input.RequestBody, &icbcBillQueryParam) svc := bankapi.GetICBCService(utils.DBE) var datainfo DataInfo ret := svc.GetBillList(icbcBillQueryParam.CommercialNo) json.Unmarshal(ret, &datainfo) this.Data["json"] = &datainfo this.ServeJSON() } // @Title 支付成功回调 // @Description post bills by token // @Success 200 {object} BILLs // @router /update-bill-list [post] func (this *ICBCController) UpdateBillList() { var billParamsICBC bankapi.BillReceiveMoneyParamsICBC var billParams bankapi.BillReceiveMoneyParams fmt.Println("RequestBody:= " + string(this.Ctx.Input.RequestBody)) json.Unmarshal(this.Ctx.Input.RequestBody, &billParamsICBC) billParams.BankName = billParamsICBC.BankName billParams.BankSerialNum = billParamsICBC.BankSerialNum billParams.Ids = billParamsICBC.Ids billParams.PayMode = billParamsICBC.PayMode billParams.ReceiveAmount,_ = strconv.ParseFloat(billParamsICBC.ReceiveAmount, 64) billParams.PayDate, _= time.Parse("2006-01-02", billParamsICBC.PayDate) svc := bankapi.GetICBCService(utils.DBE) var errinfo ErrorInfo ret := svc.ReceiveMoneyBillList(billParams) json.Unmarshal(ret, &errinfo) this.Data["json"] = &errinfo this.ServeJSON() } // @Title 对账后有未更改状态的,对账异常后再次回调 // @Description post bills by token // @Success 200 {object} BILLs // @router /update-bill-again [post] func (this *ICBCController) UpdateBillListAgain() { var billParams bankapi.BillReceiveMoneyAgainParams json.Unmarshal(this.Ctx.Input.RequestBody, &billParams) svc := bankapi.GetICBCService(utils.DBE) var errinfo ErrorInfo ret := svc.ReceiveMoneyAgain(billParams) json.Unmarshal(ret, &errinfo) this.Data["json"] = &errinfo this.ServeJSON() } // @Title 对账 // @Description 对账 // @Success 200 {object} controllers.Request // @router /check-money-list [post] func (this *ICBCController) CheckMoneyList() { svc := bankapi.GetICBCService(utils.DBE) var checkMoneyParams bankapi.BillCheckMoneyParams var checkMoneyParamsICBC bankapi.BillCheckMoneyParamsICBC var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &checkMoneyParamsICBC) checkMoneyParams.EndTime, _ = time.Parse("2006-01-02", checkMoneyParamsICBC.EndTime) checkMoneyParams.StartTime, _ = time.Parse("2006-01-02", checkMoneyParamsICBC.StartTime) var datainfo DataInfo ret := svc.CheckMoneyBillList(checkMoneyParams) json.Unmarshal(ret, &datainfo) this.Data["json"] = &datainfo this.ServeJSON() } // @Title 获取token // @Description 获取token // @Success 200 {object} string // @router /get-icbc-gfgl2019-token [post] func (this *ICBCController) GetAuthToken() { var userToken models.UserToken var user4CreateToken models.User4CreateToken var jsonBlob = this.Ctx.Input.RequestBody json.Unmarshal(jsonBlob, &user4CreateToken) //先登录 tokenParams, _ := json.Marshal(user4CreateToken) strTokenParams := string(tokenParams) svc := bankapi.GetICBCService(utils.DBE) retToken := svc.Post("/auth", strTokenParams, "") p, _ := ioutil.ReadAll(retToken.Body) json.Unmarshal(p, &userToken) if userToken.Token == "" { this.Data["json"] = "" this.ServeJSON() } else { userToken, _ := models.CreateToken(user4CreateToken.Username) this.Data["json"] = userToken this.ServeJSON() } } // @Title 对账 // @Description 对账 // @Success 200 {object} controllers.Request // @router /check-bill-list [post] func (this *ICBCController) CheckBillList() { var VerifyBillItem []bankapi.OilVerifyBillICBC fmt.Println("RequestBody:= " + string(this.Ctx.Input.RequestBody)) json.Unmarshal(this.Ctx.Input.RequestBody, &VerifyBillItem) var Oilverifybill = make([]paymentinfo.OilVerifyBill, len(VerifyBillItem)) for idx,item := range VerifyBillItem { Oilverifybill[idx].BillIds = item.BillIds Oilverifybill[idx].BankSerialNum = item.BankSerialNum Oilverifybill[idx].ReceiveAmount,_ = strconv.ParseFloat(item.ReceiveAmount, 64) loc,_ := time.LoadLocation("Local") Oilverifybill[idx].PayDate,_ = time.ParseInLocation("2006-01-02 15:04:05", item.PayDate, loc) Oilverifybill[idx].VerifyDate,_ = time.ParseInLocation("2006-01-02 15:04:05", item.VerifyDate, loc) } svc := bankapi.GetICBCService(utils.DBE) var errinfo ErrorInfo ret := svc.ReceiveVerifyBillList(Oilverifybill) json.Unmarshal(ret, &errinfo) this.Data["json"] = &errinfo this.ServeJSON() }