package hdl import ( "applet/app/admin/lib/validate" svc2 "applet/app/admin/svc/enterprise_manage" "applet/app/customer/md" "applet/app/customer/svc" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/enum" svc3 "applet/app/svc" "applet/app/utils" "context" "fmt" "github.com/chromedp/chromedp" "github.com/chromedp/chromedp/device" "github.com/gin-gonic/gin" "github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/services/certificates" "github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/jsapi" "io/ioutil" "strconv" "time" ) func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(c *gin.Context) { //查询出所有的用户身份 selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} selfSupportForUserFaceInfoDb.Set(0) list, err2 := selfSupportForUserFaceInfoDb.FindSchoolFacePaymentStatus(18, "OPEN") if err2 != nil { e.OutErr(c, e.ERR, err2.Error()) return } userIdentityDb := db.UserIdentityDb{} userIdentityDb.Set(0) for _, v := range *list { identity, err := userIdentityDb.GetUserIdentity(v.UserIdentityId) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var req = md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq{ FaceUid: v.UserId, ParentUid: v.ParentUserId, ParentLogonId: v.ParentLogonId, RosterName: identity.Name, OutRosterCode: utils.IntToStr(identity.Id), SchoolCode: v.SchoolCode, SchoolName: "珠海市斗门区第二实验小学", ScanFacePayStatus: "ON", FaceOpenStatus: "ON", } err, resp := svc.CurlAlipayPlanetEcocampusApiRosterSignUpInfo(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if err != nil { e.OutErr(c, e.ERR, err.Error()) return } fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>", utils.SerializeStr(resp)) } e.OutSuc(c, "success", nil) return var req md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } err, resp := svc.CurlAlipayPlanetEcocampusApiRosterSignUpInfo(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, resp, nil) return } func DownloadCertificates(c *gin.Context) { client, err := svc3.NewWxPayClient(c) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } // 发送请求,以下载微信支付平台证书为例 apiSvc := certificates.CertificatesApiService{Client: client} resp, result, err := apiSvc.DownloadCertificates(c) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } println("status=%d resp=%s", result.Response.StatusCode, resp) e.OutSuc(c, map[string]interface{}{ "resp": resp, }, nil) return } func WxPay(c *gin.Context) { client, err := svc3.NewWxPayClient(c) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } wxSvc := jsapi.JsapiApiService{Client: client} sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpAppId, enum.WxSpMchId, enum.WxAppletAppId, enum.WxMchId) resp, result, err := wxSvc.Prepay(c, jsapi.PrepayRequest{ SpAppid: core.String(sysCfg[enum.WxSpAppId]), SpMchid: core.String(sysCfg[enum.WxSpMchId]), SubAppid: core.String(sysCfg[enum.WxAppletAppId]), SubMchid: core.String(sysCfg[enum.WxMchId]), Description: core.String("Image形象店-深圳腾大-QQ公仔"), OutTradeNo: core.String(strconv.FormatInt(time.Now().Unix(), 10)), TimeExpire: core.Time(time.Now()), Attach: core.String("自定义数据说明"), NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"), Amount: &jsapi.Amount{ Currency: core.String("CNY"), Total: core.Int64(100), }, Payer: &jsapi.Payer{ //SpOpenid: core.String("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"), SubOpenid: core.String("o0mnM4nlX9W5HXbagffM9eTDHaPo"), }, }, ) if err != nil { // 处理错误 e.OutErr(c, e.ERR, err.Error()) return } else { // 处理返回结果 println("status=%d resp=%s", result.Response.StatusCode, resp) } return } func Demo(c *gin.Context) { sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() client, err := svc3.NewWxPayClient(c) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } wxSvc := jsapi.JsapiApiService{Client: client} var m []model.CentralKitchenForSchoolPackageOrd eg := db.Db if err1 := eg.Where("state = 1 AND create_at < '2024-04-01 23:59:59' and pay_at ='2024-03-06 17:40:47'").Desc("id").Find(&m); err1 != nil { e.OutErr(c, e.ERR, err1.Error()) return } companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{} companyWithWxpayInfoDb.Set() sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchId) centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} for _, v := range m { if v.PayWay == 1 { v.PayAt = v.CreateAt } else { wxMchId, err := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(v.EnterpriseId) if err != nil { fmt.Println(err) e.OutErr(c, e.ERR, err.Error()) return } result, _, err := wxSvc.QueryOrderByOutTradeNo(c, jsapi.QueryOrderByOutTradeNoRequest{ OutTradeNo: core.String(v.OutTradeNo), SpMchid: core.String(sysCfg[enum.WxSpMchId]), SubMchid: core.String(wxMchId), }, ) if err != nil { fmt.Println(err) continue //result, _, err := wxSvc.QueryOrderByOutTradeNo(c, // jsapi.QueryOrderByOutTradeNoRequest{ // OutTradeNo: core.String(v.OutTradeNo), // SpMchid: core.String(sysCfg[enum.WxSpMchId]), // SubMchid: core.String("1663751886"), // }, //) //fmt.Println(result) //e.OutErr(c, e.ERR, err.Error()) //return } successTime, err := utils.ConvertWechatTime(*result.SuccessTime) if err != nil { fmt.Println(err) e.OutErr(c, e.ERR, err.Error()) return } v.PayAt = successTime } centralKitchenForSchoolPackageOrd.Set(v.OutTradeNo) updateAck, err := centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdUpdate(&v, "pay_at") if err != nil { fmt.Println(err) e.OutErr(c, e.ERR, err.Error()) return } fmt.Println("updateack:::::", updateAck) } return _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx("141271708763327845", "4200002114202402240122111525", "SUCCESS", "") if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return //err, info := svc.CurlEducateFacepayApply(md.CurlEducateFacepayApplyReq{ // Config: struct { // AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"` // AliPrivateKey string `json:"ali_private_key" label:"支付宝开放平台-小程序-应用私钥"` // AliPublicKey string `json:"ali_public_key" label:"支付宝开放平台-小程序-支付宝公钥"` // }{ // AliAppId: sysCfg[enum.OpenAppletAppid], // AliPrivateKey: sysCfg[enum.OpenAppletAppPrivateKey], // AliPublicKey: sysCfg[enum.OpenAppletPublicKey], // }, // FaceUid: "2088930289907324", // FaceOpenId: "", // SchoolStdCode: "3144003844", //}) //if err != nil { // e.OutErr(c, e.ERR, err.Error()) // return //} //e.OutSuc(c, info, nil) //return err, info := svc.CurlEducateSceneTokenQueryV2(md.CurlEducateSceneTokenReq{ Config: struct { AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"` AliPrivateKey string `json:"ali_private_key" label:"支付宝开放平台-小程序-应用私钥"` AliPublicKey string `json:"ali_public_key" label:"支付宝开放平台-小程序-支付宝公钥"` }{ AliAppId: sysCfg[enum.OpenAppletAppid], AliPrivateKey: sysCfg[enum.OpenAppletAppPrivateKey], AliPublicKey: sysCfg[enum.OpenAppletPublicKey], }, CertType: "1", CertNo: "440402201102199098", StudentName: "陈子豪", OutUserId: "16141", SchoolStdCode: "3144003844", }, &model.UserIdentity{}, "", "") if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, info, nil) return ordNo := c.DefaultQuery("ord_no", "") svc2.JudgePackageOrdOrdState(ordNo) e.OutSuc(c, nil, nil) return } func SanHu(c *gin.Context) { //实现网页截图 url := c.DefaultQuery("url", "") if url == "" { e.OutErr(c, e.ERR_NO_DATA, "网址不能为空") return } ctx, cancel := chromedp.NewContext(context.Background()) defer cancel() var b1, b2 []byte if err := chromedp.Run(ctx, // emulate iPhone 7 landscape chromedp.Emulate(device.IPhone8Plus), chromedp.Navigate(url), chromedp.CaptureScreenshot(&b1), // reset chromedp.Emulate(device.Reset), // set really large viewport chromedp.EmulateViewport(1920, 2000), chromedp.Navigate(url), chromedp.CaptureScreenshot(&b2), ); err != nil { e.OutErr(c, e.ERR, err.Error()) return } if err := ioutil.WriteFile("./static/template/sanHu/IPhone8Plus.png", b1, 0777); err != nil { e.OutErr(c, e.ERR, err.Error()) return } if err := ioutil.WriteFile("./static/template/sanHu/Pc.png", b2, 0777); err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "iphone8_plus": "https://zs.zehaochi.net/template/sanHu/IPhone8Plus.png", "Pc": "https://zs.zehaochi.net/template/sanHu/Pc.png", }, nil) return }