智慧食堂
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.

318 lines
9.2 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. client, err := svc3.NewWxPayClient(c)
  146. if err != nil {
  147. e.OutErr(c, e.ERR, err.Error())
  148. return
  149. }
  150. wxSvc := jsapi.JsapiApiService{Client: client}
  151. var m []model.CentralKitchenForSchoolPackageOrd
  152. eg := db.Db
  153. 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 {
  154. e.OutErr(c, e.ERR, err1.Error())
  155. return
  156. }
  157. companyWithWxpayInfoDb := db.CompanyWithWxpayInfoDb{}
  158. companyWithWxpayInfoDb.Set()
  159. sysCfg := sysCfgDb.SysCfgFindWithDb(enum.WxSpMchId)
  160. centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{}
  161. for _, v := range m {
  162. if v.PayWay == 1 {
  163. v.PayAt = v.CreateAt
  164. } else {
  165. wxMchId, err := companyWithWxpayInfoDb.GetCompanyWithWxpayInfoByEnterprise(v.EnterpriseId)
  166. if err != nil {
  167. fmt.Println(err)
  168. e.OutErr(c, e.ERR, err.Error())
  169. return
  170. }
  171. result, _, err := wxSvc.QueryOrderByOutTradeNo(c,
  172. jsapi.QueryOrderByOutTradeNoRequest{
  173. OutTradeNo: core.String(v.OutTradeNo),
  174. SpMchid: core.String(sysCfg[enum.WxSpMchId]),
  175. SubMchid: core.String(wxMchId),
  176. },
  177. )
  178. if err != nil {
  179. fmt.Println(err)
  180. continue
  181. //result, _, err := wxSvc.QueryOrderByOutTradeNo(c,
  182. // jsapi.QueryOrderByOutTradeNoRequest{
  183. // OutTradeNo: core.String(v.OutTradeNo),
  184. // SpMchid: core.String(sysCfg[enum.WxSpMchId]),
  185. // SubMchid: core.String("1663751886"),
  186. // },
  187. //)
  188. //fmt.Println(result)
  189. //e.OutErr(c, e.ERR, err.Error())
  190. //return
  191. }
  192. successTime, err := utils.ConvertWechatTime(*result.SuccessTime)
  193. if err != nil {
  194. fmt.Println(err)
  195. e.OutErr(c, e.ERR, err.Error())
  196. return
  197. }
  198. v.PayAt = successTime
  199. }
  200. centralKitchenForSchoolPackageOrd.Set(v.OutTradeNo)
  201. updateAck, err := centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdUpdate(&v, "pay_at")
  202. if err != nil {
  203. fmt.Println(err)
  204. e.OutErr(c, e.ERR, err.Error())
  205. return
  206. }
  207. fmt.Println("updateack:::::", updateAck)
  208. }
  209. return
  210. _, err = svc.DealCentralKitchenForSchoolOrderCallBackForWx("141271708763327845", "4200002114202402240122111525", "SUCCESS", "")
  211. if err != nil {
  212. e.OutErr(c, e.ERR, err.Error())
  213. return
  214. }
  215. e.OutSuc(c, "success", nil)
  216. return
  217. //err, info := svc.CurlEducateFacepayApply(md.CurlEducateFacepayApplyReq{
  218. // Config: struct {
  219. // AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"`
  220. // AliPrivateKey string `json:"ali_private_key" label:"支付宝开放平台-小程序-应用私钥"`
  221. // AliPublicKey string `json:"ali_public_key" label:"支付宝开放平台-小程序-支付宝公钥"`
  222. // }{
  223. // AliAppId: sysCfg[enum.OpenAppletAppid],
  224. // AliPrivateKey: sysCfg[enum.OpenAppletAppPrivateKey],
  225. // AliPublicKey: sysCfg[enum.OpenAppletPublicKey],
  226. // },
  227. // FaceUid: "2088930289907324",
  228. // FaceOpenId: "",
  229. // SchoolStdCode: "3144003844",
  230. //})
  231. //if err != nil {
  232. // e.OutErr(c, e.ERR, err.Error())
  233. // return
  234. //}
  235. //e.OutSuc(c, info, nil)
  236. //return
  237. err, info := svc.CurlEducateSceneTokenQueryV2(md.CurlEducateSceneTokenReq{
  238. Config: struct {
  239. AliAppId string `json:"ali_app_id" label:"支付宝开放平台-小程序-appid"`
  240. AliPrivateKey string `json:"ali_private_key" label:"支付宝开放平台-小程序-应用私钥"`
  241. AliPublicKey string `json:"ali_public_key" label:"支付宝开放平台-小程序-支付宝公钥"`
  242. }{
  243. AliAppId: sysCfg[enum.OpenAppletAppid],
  244. AliPrivateKey: sysCfg[enum.OpenAppletAppPrivateKey],
  245. AliPublicKey: sysCfg[enum.OpenAppletPublicKey],
  246. },
  247. CertType: "1",
  248. CertNo: "440402201102199098",
  249. StudentName: "陈子豪",
  250. OutUserId: "16141",
  251. SchoolStdCode: "3144003844",
  252. }, &model.UserIdentity{}, "", "")
  253. if err != nil {
  254. e.OutErr(c, e.ERR, err.Error())
  255. return
  256. }
  257. e.OutSuc(c, info, nil)
  258. return
  259. ordNo := c.DefaultQuery("ord_no", "")
  260. svc2.JudgePackageOrdOrdState(ordNo, nil)
  261. e.OutSuc(c, nil, nil)
  262. return
  263. }
  264. func SanHu(c *gin.Context) { //实现网页截图
  265. url := c.DefaultQuery("url", "")
  266. if url == "" {
  267. e.OutErr(c, e.ERR_NO_DATA, "网址不能为空")
  268. return
  269. }
  270. ctx, cancel := chromedp.NewContext(context.Background())
  271. defer cancel()
  272. var b1, b2 []byte
  273. if err := chromedp.Run(ctx,
  274. // emulate iPhone 7 landscape
  275. chromedp.Emulate(device.IPhone8Plus),
  276. chromedp.Navigate(url),
  277. chromedp.CaptureScreenshot(&b1),
  278. // reset
  279. chromedp.Emulate(device.Reset),
  280. // set really large viewport
  281. chromedp.EmulateViewport(1920, 2000),
  282. chromedp.Navigate(url),
  283. chromedp.CaptureScreenshot(&b2),
  284. ); err != nil {
  285. e.OutErr(c, e.ERR, err.Error())
  286. return
  287. }
  288. if err := ioutil.WriteFile("./static/template/sanHu/IPhone8Plus.png", b1, 0777); err != nil {
  289. e.OutErr(c, e.ERR, err.Error())
  290. return
  291. }
  292. if err := ioutil.WriteFile("./static/template/sanHu/Pc.png", b2, 0777); err != nil {
  293. e.OutErr(c, e.ERR, err.Error())
  294. return
  295. }
  296. e.OutSuc(c, map[string]interface{}{
  297. "iphone8_plus": "https://zs.zehaochi.net/template/sanHu/IPhone8Plus.png",
  298. "Pc": "https://zs.zehaochi.net/template/sanHu/Pc.png",
  299. }, nil)
  300. return
  301. }