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

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