智慧食堂
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

hdl_demo.go 6.3 KiB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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/db/model"
  9. "applet/app/e"
  10. "applet/app/enum"
  11. svc3 "applet/app/svc"
  12. "applet/app/utils"
  13. "context"
  14. "fmt"
  15. "github.com/chromedp/chromedp"
  16. "github.com/chromedp/chromedp/device"
  17. "github.com/gin-gonic/gin"
  18. "github.com/wechatpay-apiv3/wechatpay-go/core"
  19. "github.com/wechatpay-apiv3/wechatpay-go/services/certificates"
  20. "github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/jsapi"
  21. "io/ioutil"
  22. "strconv"
  23. "time"
  24. )
  25. func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(c *gin.Context) {
  26. //查询出所有的用户身份
  27. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  28. selfSupportForUserFaceInfoDb.Set(0)
  29. list, err2 := selfSupportForUserFaceInfoDb.FindSchoolFacePaymentStatus(18, "OPEN")
  30. if err2 != nil {
  31. e.OutErr(c, e.ERR, err2.Error())
  32. return
  33. }
  34. userIdentityDb := db.UserIdentityDb{}
  35. userIdentityDb.Set(0)
  36. for _, v := range *list {
  37. identity, err := userIdentityDb.GetUserIdentity(v.UserIdentityId)
  38. if err != nil {
  39. e.OutErr(c, e.ERR, err.Error())
  40. return
  41. }
  42. var req = md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq{
  43. FaceUid: v.UserId,
  44. ParentUid: v.ParentUserId,
  45. ParentLogonId: v.ParentLogonId,
  46. RosterName: identity.Name,
  47. OutRosterCode: utils.IntToStr(identity.Id),
  48. SchoolCode: v.SchoolCode,
  49. SchoolName: "珠海市斗门区第二实验小学",
  50. ScanFacePayStatus: "ON",
  51. FaceOpenStatus: "ON",
  52. }
  53. err, resp := svc.CurlAlipayPlanetEcocampusApiRosterSignUpInfo(req)
  54. if err != nil {
  55. e.OutErr(c, e.ERR, err.Error())
  56. return
  57. }
  58. if err != nil {
  59. e.OutErr(c, e.ERR, err.Error())
  60. return
  61. }
  62. fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>", utils.SerializeStr(resp))
  63. }
  64. e.OutSuc(c, "success", nil)
  65. return
  66. var req md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq
  67. err := c.ShouldBindJSON(&req)
  68. if err != nil {
  69. err = validate.HandleValidateErr(err)
  70. err1 := err.(e.E)
  71. e.OutErr(c, err1.Code, err1.Error())
  72. return
  73. }
  74. err, resp := svc.CurlAlipayPlanetEcocampusApiRosterSignUpInfo(req)
  75. if err != nil {
  76. e.OutErr(c, e.ERR, err.Error())
  77. return
  78. }
  79. e.OutSuc(c, resp, nil)
  80. return
  81. }
  82. func DownloadCertificates(c *gin.Context) {
  83. client, err := svc3.NewWxPayClient(c)
  84. if err != nil {
  85. e.OutErr(c, e.ERR, err.Error())
  86. return
  87. }
  88. // 发送请求,以下载微信支付平台证书为例
  89. apiSvc := certificates.CertificatesApiService{Client: client}
  90. resp, result, err := apiSvc.DownloadCertificates(c)
  91. if err != nil {
  92. e.OutErr(c, e.ERR, err.Error())
  93. return
  94. }
  95. println("status=%d resp=%s", result.Response.StatusCode, resp)
  96. e.OutSuc(c, map[string]interface{}{
  97. "resp": resp,
  98. }, nil)
  99. return
  100. }
  101. func WxPay(c *gin.Context) {
  102. client, err := svc3.NewWxPayClient(c)
  103. if err != nil {
  104. e.OutErr(c, e.ERR, err.Error())
  105. return
  106. }
  107. wxSvc := jsapi.JsapiApiService{Client: client}
  108. sysCfgDb := db.SysCfgDb{}
  109. sysCfgDb.Set()
  110. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpAppId, enum.WxSpMchId, enum.WxAppletAppId, enum.WxMchId)
  111. resp, result, err := wxSvc.Prepay(c,
  112. jsapi.PrepayRequest{
  113. SpAppid: core.String(sysCfg[enum.WxSpAppId]),
  114. SpMchid: core.String(sysCfg[enum.WxSpMchId]),
  115. SubAppid: core.String(sysCfg[enum.WxAppletAppId]),
  116. SubMchid: core.String(sysCfg[enum.WxMchId]),
  117. Description: core.String("Image形象店-深圳腾大-QQ公仔"),
  118. OutTradeNo: core.String(strconv.FormatInt(time.Now().Unix(), 10)),
  119. TimeExpire: core.Time(time.Now()),
  120. Attach: core.String("自定义数据说明"),
  121. NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"),
  122. Amount: &jsapi.Amount{
  123. Currency: core.String("CNY"),
  124. Total: core.Int64(100),
  125. },
  126. Payer: &jsapi.Payer{
  127. //SpOpenid: core.String("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"),
  128. SubOpenid: core.String("o0mnM4nlX9W5HXbagffM9eTDHaPo"),
  129. },
  130. },
  131. )
  132. if err != nil {
  133. // 处理错误
  134. e.OutErr(c, e.ERR, err.Error())
  135. return
  136. } else {
  137. // 处理返回结果
  138. println("status=%d resp=%s", result.Response.StatusCode, resp)
  139. }
  140. return
  141. }
  142. func Demo(c *gin.Context) {
  143. sysCfgDb := db.SysCfgDb{}
  144. sysCfgDb.Set()
  145. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.OpenAppletAppid, enum.OpenAppletAppPrivateKey, enum.OpenAppletPublicKey)
  146. err, info := svc.CurlEducateSceneTokenQueryV2(md.CurlEducateSceneTokenReq{
  147. Config: struct {
  148. AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"`
  149. AliPrivateKey string `json:"ali_private_key" label:"支付宝开放平台-小程序-应用私钥"`
  150. AliPublicKey string `json:"ali_public_key" label:"支付宝开放平台-小程序-支付宝公钥"`
  151. }{
  152. AliAppId: sysCfg[enum.OpenAppletAppid],
  153. AliPrivateKey: sysCfg[enum.OpenAppletAppPrivateKey],
  154. AliPublicKey: sysCfg[enum.OpenAppletPublicKey],
  155. },
  156. CertType: "A",
  157. CertNo: "440881201010205523",
  158. StudentName: "龙佩滢",
  159. OutUserId: "1001",
  160. SchoolStdCode: "12440403MB2D752515",
  161. }, &model.UserIdentity{}, "", "")
  162. if err != nil {
  163. e.OutErr(c, e.ERR, err.Error())
  164. return
  165. }
  166. e.OutSuc(c, info, nil)
  167. return
  168. ordNo := c.DefaultQuery("ord_no", "")
  169. svc2.JudgePackageOrdOrdState(ordNo)
  170. e.OutSuc(c, nil, nil)
  171. return
  172. }
  173. func SanHu(c *gin.Context) { //实现网页截图
  174. url := c.DefaultQuery("url", "")
  175. if url == "" {
  176. e.OutErr(c, e.ERR_NO_DATA, "网址不能为空")
  177. return
  178. }
  179. ctx, cancel := chromedp.NewContext(context.Background())
  180. defer cancel()
  181. var b1, b2 []byte
  182. if err := chromedp.Run(ctx,
  183. // emulate iPhone 7 landscape
  184. chromedp.Emulate(device.IPhone8Plus),
  185. chromedp.Navigate(url),
  186. chromedp.CaptureScreenshot(&b1),
  187. // reset
  188. chromedp.Emulate(device.Reset),
  189. // set really large viewport
  190. chromedp.EmulateViewport(1920, 2000),
  191. chromedp.Navigate(url),
  192. chromedp.CaptureScreenshot(&b2),
  193. ); err != nil {
  194. e.OutErr(c, e.ERR, err.Error())
  195. return
  196. }
  197. if err := ioutil.WriteFile("./static/template/sanHu/IPhone8Plus.png", b1, 0777); err != nil {
  198. e.OutErr(c, e.ERR, err.Error())
  199. return
  200. }
  201. if err := ioutil.WriteFile("./static/template/sanHu/Pc.png", b2, 0777); err != nil {
  202. e.OutErr(c, e.ERR, err.Error())
  203. return
  204. }
  205. e.OutSuc(c, map[string]interface{}{
  206. "iphone8_plus": "https://zs.zehaochi.net/template/sanHu/IPhone8Plus.png",
  207. "Pc": "https://zs.zehaochi.net/template/sanHu/Pc.png",
  208. }, nil)
  209. return
  210. }