智慧食堂
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

246 linhas
7.1 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/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.CurlEducateFacepayApply(md.CurlEducateFacepayApplyReq{
  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. // FaceUid: "2088930289907324",
  157. // FaceOpenId: "",
  158. // SchoolStdCode: "3144003844",
  159. //})
  160. //if err != nil {
  161. // e.OutErr(c, e.ERR, err.Error())
  162. // return
  163. //}
  164. //e.OutSuc(c, info, nil)
  165. //return
  166. err, info := svc.CurlEducateSceneTokenQueryV2(md.CurlEducateSceneTokenReq{
  167. Config: struct {
  168. AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"`
  169. AliPrivateKey string `json:"ali_private_key" label:"支付宝开放平台-小程序-应用私钥"`
  170. AliPublicKey string `json:"ali_public_key" label:"支付宝开放平台-小程序-支付宝公钥"`
  171. }{
  172. AliAppId: sysCfg[enum.OpenAppletAppid],
  173. AliPrivateKey: sysCfg[enum.OpenAppletAppPrivateKey],
  174. AliPublicKey: sysCfg[enum.OpenAppletPublicKey],
  175. },
  176. CertType: "1",
  177. CertNo: "440402201102199098",
  178. StudentName: "陈子豪",
  179. OutUserId: "16141",
  180. SchoolStdCode: "3144003844",
  181. }, &model.UserIdentity{}, "", "")
  182. if err != nil {
  183. e.OutErr(c, e.ERR, err.Error())
  184. return
  185. }
  186. e.OutSuc(c, info, nil)
  187. return
  188. ordNo := c.DefaultQuery("ord_no", "")
  189. svc2.JudgePackageOrdOrdState(ordNo)
  190. e.OutSuc(c, nil, nil)
  191. return
  192. }
  193. func SanHu(c *gin.Context) { //实现网页截图
  194. url := c.DefaultQuery("url", "")
  195. if url == "" {
  196. e.OutErr(c, e.ERR_NO_DATA, "网址不能为空")
  197. return
  198. }
  199. ctx, cancel := chromedp.NewContext(context.Background())
  200. defer cancel()
  201. var b1, b2 []byte
  202. if err := chromedp.Run(ctx,
  203. // emulate iPhone 7 landscape
  204. chromedp.Emulate(device.IPhone8Plus),
  205. chromedp.Navigate(url),
  206. chromedp.CaptureScreenshot(&b1),
  207. // reset
  208. chromedp.Emulate(device.Reset),
  209. // set really large viewport
  210. chromedp.EmulateViewport(1920, 2000),
  211. chromedp.Navigate(url),
  212. chromedp.CaptureScreenshot(&b2),
  213. ); err != nil {
  214. e.OutErr(c, e.ERR, err.Error())
  215. return
  216. }
  217. if err := ioutil.WriteFile("./static/template/sanHu/IPhone8Plus.png", b1, 0777); err != nil {
  218. e.OutErr(c, e.ERR, err.Error())
  219. return
  220. }
  221. if err := ioutil.WriteFile("./static/template/sanHu/Pc.png", b2, 0777); err != nil {
  222. e.OutErr(c, e.ERR, err.Error())
  223. return
  224. }
  225. e.OutSuc(c, map[string]interface{}{
  226. "iphone8_plus": "https://zs.zehaochi.net/template/sanHu/IPhone8Plus.png",
  227. "Pc": "https://zs.zehaochi.net/template/sanHu/Pc.png",
  228. }, nil)
  229. return
  230. }