智慧食堂
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

153 řádky
4.0 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/lib/validate"
  4. svc2 "applet/app/admin/svc/enterprise_manage"
  5. "applet/app/customer/md"
  6. "applet/app/customer/svc"
  7. "applet/app/db"
  8. "applet/app/e"
  9. "applet/app/enum"
  10. svc3 "applet/app/svc"
  11. "context"
  12. "github.com/chromedp/chromedp"
  13. "github.com/chromedp/chromedp/device"
  14. "github.com/gin-gonic/gin"
  15. "github.com/wechatpay-apiv3/wechatpay-go/core"
  16. "github.com/wechatpay-apiv3/wechatpay-go/services/certificates"
  17. "github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/jsapi"
  18. "io/ioutil"
  19. "time"
  20. )
  21. func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(c *gin.Context) {
  22. var req md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq
  23. err := c.ShouldBindJSON(&req)
  24. if err != nil {
  25. err = validate.HandleValidateErr(err)
  26. err1 := err.(e.E)
  27. e.OutErr(c, err1.Code, err1.Error())
  28. return
  29. }
  30. err, resp := svc.CurlAlipayPlanetEcocampusApiRosterSignUpInfo(req)
  31. if err != nil {
  32. e.OutErr(c, e.ERR, err.Error())
  33. return
  34. }
  35. e.OutSuc(c, resp, nil)
  36. return
  37. }
  38. func DownloadCertificates(c *gin.Context) {
  39. client, err := svc3.NewWxPayClient(c)
  40. if err != nil {
  41. e.OutErr(c, e.ERR, err.Error())
  42. return
  43. }
  44. // 发送请求,以下载微信支付平台证书为例
  45. apiSvc := certificates.CertificatesApiService{Client: client}
  46. resp, result, err := apiSvc.DownloadCertificates(c)
  47. if err != nil {
  48. e.OutErr(c, e.ERR, err.Error())
  49. return
  50. }
  51. println("status=%d resp=%s", result.Response.StatusCode, resp)
  52. e.OutSuc(c, map[string]interface{}{
  53. "resp": resp,
  54. }, nil)
  55. return
  56. }
  57. func WxPay(c *gin.Context) {
  58. client, err := svc3.NewWxPayClient(c)
  59. if err != nil {
  60. e.OutErr(c, e.ERR, err.Error())
  61. return
  62. }
  63. wxSvc := jsapi.JsapiApiService{Client: client}
  64. sysCfgDb := db.SysCfgDb{}
  65. sysCfgDb.Set()
  66. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpAppId, enum.WxSpMchId, enum.WxAppletAppId, enum.WxMchId)
  67. resp, result, err := wxSvc.Prepay(c,
  68. jsapi.PrepayRequest{
  69. SpAppid: core.String(sysCfg[enum.WxSpAppId]),
  70. SpMchid: core.String(sysCfg[enum.WxSpMchId]),
  71. SubAppid: core.String(sysCfg[enum.WxAppletAppId]),
  72. SubMchid: core.String(sysCfg[enum.WxMchId]),
  73. Description: core.String("Image形象店-深圳腾大-QQ公仔"),
  74. OutTradeNo: core.String("1217752501201407033233368018"),
  75. TimeExpire: core.Time(time.Now()),
  76. Attach: core.String("自定义数据说明"),
  77. NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"),
  78. Amount: &jsapi.Amount{
  79. Currency: core.String("CNY"),
  80. Total: core.Int64(100),
  81. },
  82. Payer: &jsapi.Payer{
  83. //SpOpenid: core.String("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"),
  84. SubOpenid: core.String("o0mnM4nlX9W5HXbagffM9eTDHaPo"),
  85. },
  86. },
  87. )
  88. if err != nil {
  89. // 处理错误
  90. e.OutErr(c, e.ERR, err.Error())
  91. return
  92. } else {
  93. // 处理返回结果
  94. println("status=%d resp=%s", result.Response.StatusCode, resp)
  95. }
  96. return
  97. }
  98. func Demo(c *gin.Context) {
  99. ordNo := c.DefaultQuery("ord_no", "")
  100. svc2.JudgePackageOrdOrdState(ordNo)
  101. e.OutSuc(c, nil, nil)
  102. return
  103. }
  104. func SanHu(c *gin.Context) { //实现网页截图
  105. url := c.DefaultQuery("url", "")
  106. if url == "" {
  107. e.OutErr(c, e.ERR_NO_DATA, "网址不能为空")
  108. return
  109. }
  110. ctx, cancel := chromedp.NewContext(context.Background())
  111. defer cancel()
  112. var b1, b2 []byte
  113. if err := chromedp.Run(ctx,
  114. // emulate iPhone 7 landscape
  115. chromedp.Emulate(device.IPhone8Plus),
  116. chromedp.Navigate(url),
  117. chromedp.CaptureScreenshot(&b1),
  118. // reset
  119. chromedp.Emulate(device.Reset),
  120. // set really large viewport
  121. chromedp.EmulateViewport(1920, 2000),
  122. chromedp.Navigate(url),
  123. chromedp.CaptureScreenshot(&b2),
  124. ); err != nil {
  125. e.OutErr(c, e.ERR, err.Error())
  126. return
  127. }
  128. if err := ioutil.WriteFile("./static/template/sanHu/IPhone8Plus.png", b1, 0777); err != nil {
  129. e.OutErr(c, e.ERR, err.Error())
  130. return
  131. }
  132. if err := ioutil.WriteFile("./static/template/sanHu/Pc.png", b2, 0777); err != nil {
  133. e.OutErr(c, e.ERR, err.Error())
  134. return
  135. }
  136. e.OutSuc(c, map[string]interface{}{
  137. "iphone8_plus": "https://zs.zehaochi.net/template/sanHu/IPhone8Plus.png",
  138. "Pc": "https://zs.zehaochi.net/template/sanHu/Pc.png",
  139. }, nil)
  140. return
  141. }