智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_demo.go 4.1 KiB

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