智慧食堂
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

svc_curl_smart_pay.go 13 KiB

vor 1 Jahr
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. package svc
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/customer/md"
  5. "applet/app/db"
  6. "applet/app/db/model"
  7. "applet/app/utils"
  8. "encoding/json"
  9. "errors"
  10. "time"
  11. )
  12. func AesDecrypt(args md.CurlAesDecrypt) (error, interface{}) {
  13. url := cfg.SmartCanteenPay + "/alipay/decrypt/index"
  14. utils.FilePutContents("AesDecrypt", utils.SerializeStr(map[string]interface{}{
  15. "data": args,
  16. }))
  17. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  18. if err != nil {
  19. return err, nil
  20. }
  21. var result struct {
  22. Code int `json:"code"`
  23. Msg string `json:"msg"`
  24. Data interface{} `json:"data"`
  25. }
  26. utils.FilePutContents("AesDecrypt", utils.SerializeStr(result))
  27. err = json.Unmarshal(bytes, &result)
  28. if err != nil {
  29. return err, nil
  30. }
  31. if result.Code != 0 {
  32. if result.Msg != "" {
  33. return errors.New(result.Msg), nil
  34. }
  35. return errors.New("请求智慧餐厅支付 异常/失败"), nil
  36. }
  37. return nil, result.Data
  38. }
  39. func SystemOauthToken(args md.SystemOauthTokenReq) (error, interface{}) {
  40. url := cfg.SmartCanteenPay + "/alipay/systemOauthToken/index"
  41. utils.FilePutContents("SystemOauthToken", utils.SerializeStr(map[string]interface{}{
  42. "data": args,
  43. }))
  44. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  45. if err != nil {
  46. return err, nil
  47. }
  48. var result struct {
  49. Code int `json:"code"`
  50. Msg string `json:"msg"`
  51. Data interface{} `json:"data"`
  52. }
  53. utils.FilePutContents("SystemOauthToken", utils.SerializeStr(result))
  54. err = json.Unmarshal(bytes, &result)
  55. if err != nil {
  56. return err, nil
  57. }
  58. if result.Code != 0 {
  59. if result.Msg != "" {
  60. return errors.New(result.Msg), nil
  61. }
  62. return errors.New("请求智慧餐厅支付 异常/失败"), nil
  63. }
  64. return nil, result.Data
  65. }
  66. func CurlAlipayTradeCreate(args md.CurlAlipayTradeCreateReq) (err error, resp md.CurlAlipayTradeCreateResp) {
  67. url := cfg.SmartCanteenPay + "/alipay/pay/tradeCreate"
  68. utils.FilePutContents("CurlAlipayTradeCreate", utils.SerializeStr(map[string]interface{}{
  69. "args": args,
  70. }))
  71. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  72. if err != nil {
  73. return
  74. }
  75. var result struct {
  76. Code int `json:"code"`
  77. Msg string `json:"msg"`
  78. Data interface{} `json:"data"`
  79. }
  80. utils.FilePutContents("CurlAlipayTradeCreate", utils.SerializeStr(result))
  81. err = json.Unmarshal(bytes, &result)
  82. if err != nil {
  83. return
  84. }
  85. if result.Code != 0 {
  86. if result.Msg != "" {
  87. err = errors.New(result.Msg)
  88. return
  89. }
  90. err = errors.New("请求智慧餐厅支付 异常/失败")
  91. return
  92. }
  93. err = json.Unmarshal(utils.Serialize(result.Data), &resp)
  94. if err != nil {
  95. return
  96. }
  97. return
  98. }
  99. func CurlAlipayTradeQuery(args md.CurlAlipayTradeQueryReq) (err error, resp md.CurlAlipayTradeQueryResp) {
  100. url := cfg.SmartCanteenPay + "/alipay/pay/tradeCommonQuery"
  101. utils.FilePutContents("CurlAlipayTradeQuery", utils.SerializeStr(map[string]interface{}{
  102. "args": args,
  103. }))
  104. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  105. if err != nil {
  106. return
  107. }
  108. var result struct {
  109. Code int `json:"code"`
  110. Msg string `json:"msg"`
  111. Data interface{} `json:"data"`
  112. }
  113. utils.FilePutContents("CurlAlipayTradeQuery", utils.SerializeStr(result))
  114. err = json.Unmarshal(bytes, &result)
  115. if err != nil {
  116. return
  117. }
  118. if result.Code != 0 {
  119. if result.Msg != "" {
  120. err = errors.New(result.Msg)
  121. return
  122. }
  123. err = errors.New("请求智慧餐厅支付 异常/失败")
  124. return
  125. }
  126. err = json.Unmarshal(utils.Serialize(result.Data), &resp)
  127. if err != nil {
  128. return
  129. }
  130. return
  131. }
  132. func CurlAlipayTradeRefund(args md.CurlAlipayTradeRefundReq) (err error, resp interface{}) {
  133. url := cfg.SmartCanteenPay + "/alipay/pay/tradeRefund"
  134. utils.FilePutContents("CurlAlipayTradeRefund", utils.SerializeStr(map[string]interface{}{
  135. "args": args,
  136. }))
  137. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  138. if err != nil {
  139. return
  140. }
  141. var result struct {
  142. Code int `json:"code"`
  143. Msg string `json:"msg"`
  144. Data interface{} `json:"data"`
  145. }
  146. utils.FilePutContents("CurlAlipayTradeRefund", utils.SerializeStr(result))
  147. err = json.Unmarshal(bytes, &result)
  148. if err != nil {
  149. return
  150. }
  151. if result.Code != 0 {
  152. if result.Msg != "" {
  153. err = errors.New(result.Msg)
  154. return
  155. }
  156. err = errors.New("请求智慧餐厅支付 异常/失败")
  157. return
  158. }
  159. return nil, result.Data
  160. }
  161. func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentityId int, userToken string) (err error, resp interface{}) {
  162. utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(map[string]interface{}{
  163. "args": args,
  164. }))
  165. if userToken == "" {
  166. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  167. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  168. bytes, err1 := utils.CurlPost(url, utils.Serialize(map[string]string{
  169. "cert_no": args.CertNo,
  170. "school_std_code": args.SchoolStdCode,
  171. "student_name": args.StudentName,
  172. "out_user_id": args.OutUserId,
  173. "cert_type": "1",
  174. "sub_code": "SCHOOL_FACE_PASS_QUERY",
  175. }), nil)
  176. if err1 != nil {
  177. return
  178. }
  179. var result struct {
  180. Code int `json:"code"`
  181. Msg string `json:"msg"`
  182. Data interface{} `json:"data"`
  183. }
  184. utils.FilePutContents("CurlEducateSceneTokenCreate", utils.SerializeStr(result))
  185. err1 = json.Unmarshal(bytes, &result)
  186. if err1 != nil {
  187. return
  188. }
  189. if result.Code != 0 {
  190. if result.Msg != "" {
  191. err1 = errors.New(result.Msg)
  192. return
  193. }
  194. err1 = errors.New("请求智慧餐厅支付 异常/失败")
  195. return
  196. }
  197. resultMap, ok := result.Data.(map[string]interface{})
  198. if !ok {
  199. err1 = errors.New("获取 user_token 失败")
  200. return
  201. }
  202. if resultMap["code"].(string) != "10000" {
  203. return nil, resultMap
  204. }
  205. userToken = resultMap["token"].(string)
  206. }
  207. //2、TODO::查询用户一脸通行开通状态:根据获取到的用户信息token,使用 alipay.commerce.educate.scene.token.query 接口查询用户人脸采集状态
  208. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenQuery"
  209. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]string{
  210. "user_token": userToken,
  211. }), nil)
  212. if err != nil {
  213. return
  214. }
  215. var result1 struct {
  216. Code int `json:"code"`
  217. Msg string `json:"msg"`
  218. Data interface{} `json:"data"`
  219. }
  220. utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(result1))
  221. err = json.Unmarshal(bytes, &result1)
  222. if err != nil {
  223. return
  224. }
  225. if result1.Code != 0 {
  226. if result1.Msg != "" {
  227. err = errors.New(result1.Msg)
  228. return
  229. }
  230. err = errors.New("请求智慧餐厅支付 异常/失败")
  231. return
  232. }
  233. // 更新/新增 `self_support_for_user_facel_info`
  234. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  235. selfSupportForUserFaceInfoDb.Set(userIdentityId)
  236. info, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo()
  237. if err != nil {
  238. return
  239. }
  240. now := time.Now().Format("2006-01-02 15:04:05")
  241. var res map[string]string
  242. utils.Unserialize([]byte(utils.SerializeStr(result1.Data)), &res)
  243. if info == nil {
  244. info = &model.SelfSupportForUserFaceInfo{
  245. UserIdentityId: userIdentityId,
  246. CollectFaceType: 1,
  247. SchoolCode: res["school_code"],
  248. SchoolStdCode: res["school_std_code"],
  249. ParentUserId: res["parent_user_id"],
  250. ParentLogonId: res["parent_logon_id"],
  251. UserId: res["user_id"],
  252. SchoolFacePassStatus: res["school_face_pass_status"],
  253. SchoolFacePaymentStatus: res["school_face_payment_status"],
  254. CreateAt: now,
  255. UpdateAt: now,
  256. }
  257. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(info)
  258. if err2 != nil {
  259. return err2, nil
  260. }
  261. } else {
  262. info.ParentUserId = res["parent_user_id"]
  263. info.ParentLogonId = res["parent_logon_id"]
  264. info.UserId = res["user_id"]
  265. info.SchoolFacePassStatus = res["school_face_pass_status"]
  266. info.SchoolFacePaymentStatus = res["school_face_payment_status"]
  267. info.UpdateAt = now
  268. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "create_at")
  269. if err2 != nil {
  270. return err2, nil
  271. }
  272. }
  273. return nil, result1.Data
  274. }
  275. func CurlEducateSceneTokenCreateForApplet(args md.CurlEducateSceneTokenReq) (err error, resp interface{}) {
  276. utils.FilePutContents("CurlEducateSceneTokenCreateForApplet", utils.SerializeStr(map[string]interface{}{
  277. "args": args,
  278. }))
  279. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  280. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  281. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]string{
  282. "cert_no": args.CertNo,
  283. "school_std_code": args.SchoolStdCode,
  284. "student_name": args.StudentName,
  285. "out_user_id": args.OutUserId,
  286. "cert_type": "1",
  287. "sub_code": "SCHOOL_FACE_PASS_NAVIGATE",
  288. }), nil)
  289. if err != nil {
  290. return
  291. }
  292. var result struct {
  293. Code int `json:"code"`
  294. Msg string `json:"msg"`
  295. Data interface{} `json:"data"`
  296. }
  297. utils.FilePutContents("CurlEducateSceneTokenCreateForApplet", utils.SerializeStr(result))
  298. err = json.Unmarshal(bytes, &result)
  299. if err != nil {
  300. return
  301. }
  302. if result.Code != 0 {
  303. if result.Msg != "" {
  304. err = errors.New(result.Msg)
  305. return
  306. }
  307. err = errors.New("请求智慧餐厅支付 异常/失败")
  308. return
  309. }
  310. return nil, result.Data
  311. }
  312. func CurlEducateSceneTokenCreateForConcentratedCollectApplet(args md.CurlEducateSceneTokenReq) (err error, resp interface{}) {
  313. utils.FilePutContents("CurlEducateSceneTokenCreateForConcentratedCollectApplet", utils.SerializeStr(map[string]interface{}{
  314. "args": args,
  315. }))
  316. //1、TODO::生成用户信息token(使用 alipay.commerce.educate.scene.token.create 接口生成用户信息token)
  317. url := cfg.SmartCanteenPay + "/alipay/faceCollection/educateSceneTokenCreate"
  318. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]string{
  319. "cert_no": args.CertNo,
  320. "school_std_code": args.SchoolStdCode,
  321. "student_name": args.StudentName,
  322. "out_user_id": args.OutUserId,
  323. "cert_type": "1",
  324. "sub_code": "SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT",
  325. "operator_user_id": args.OperatorUserId, //采集人员的支付宝会员标识。(当sub_code为SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT时,当前参数必选)
  326. }), nil)
  327. if err != nil {
  328. return
  329. }
  330. var result struct {
  331. Code int `json:"code"`
  332. Msg string `json:"msg"`
  333. Data interface{} `json:"data"`
  334. }
  335. utils.FilePutContents("CurlEducateSceneTokenCreateForConcentratedCollectApplet", utils.SerializeStr(result))
  336. err = json.Unmarshal(bytes, &result)
  337. if err != nil {
  338. return
  339. }
  340. if result.Code != 0 {
  341. if result.Msg != "" {
  342. err = errors.New(result.Msg)
  343. return
  344. }
  345. err = errors.New("请求智慧餐厅支付 异常/失败")
  346. return
  347. }
  348. return nil, result.Data
  349. }
  350. func CurlEducateFacepayApply(args md.CurlEducateFacepayApplyReq) (err error, resp interface{}) {
  351. utils.FilePutContents("CurlEducateFacepayApply", utils.SerializeStr(map[string]interface{}{
  352. "args": args,
  353. }))
  354. //1、TODO::alipay.commerce.educate.facepay.apply(人脸开通支付申请)
  355. url := cfg.SmartCanteenPay + "/alipay/faceScanPay/educateFacepayApply"
  356. bytes, err := utils.CurlPost(url, utils.Serialize(map[string]string{
  357. "face_uid": args.FaceUid,
  358. "school_std_code": args.SchoolStdCode,
  359. "face_open_id": args.FaceOpenId,
  360. }), nil)
  361. if err != nil {
  362. return
  363. }
  364. var result struct {
  365. Code int `json:"code"`
  366. Msg string `json:"msg"`
  367. Data interface{} `json:"data"`
  368. }
  369. utils.FilePutContents("CurlEducateFacepayApply", utils.SerializeStr(result))
  370. err = json.Unmarshal(bytes, &result)
  371. if err != nil {
  372. return
  373. }
  374. if result.Code != 0 {
  375. if result.Msg != "" {
  376. err = errors.New(result.Msg)
  377. return
  378. }
  379. err = errors.New("请求智慧餐厅支付 异常/失败")
  380. return
  381. }
  382. return nil, result.Data
  383. }
  384. func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(args md.CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq) (err error, resp interface{}) {
  385. url := cfg.SmartCanteenPay + "/alipay/bPass/alipayPlanetEcocampusApiRosterSignUpInfo"
  386. utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSignUpInfo", utils.SerializeStr(map[string]interface{}{
  387. "args": args,
  388. }))
  389. bytes, err := utils.CurlPost(url, utils.Serialize(args), nil)
  390. if err != nil {
  391. return
  392. }
  393. var result struct {
  394. Code int `json:"code"`
  395. Msg string `json:"msg"`
  396. Data interface{} `json:"data"`
  397. }
  398. utils.FilePutContents("CurlAlipayPlanetEcocampusApiRosterSignUpInfo", utils.SerializeStr(result))
  399. err = json.Unmarshal(bytes, &result)
  400. if err != nil {
  401. return
  402. }
  403. if result.Code != 0 {
  404. if result.Msg != "" {
  405. err = errors.New(result.Msg)
  406. return
  407. }
  408. err = errors.New("请求智慧餐厅支付 异常/失败")
  409. return
  410. }
  411. return nil, result.Data
  412. }