附近小店
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_base.go 5.0 KiB

2 달 전
2 달 전
2 달 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package hdl
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. "applet/app/e"
  7. "applet/app/md"
  8. "applet/app/svc"
  9. "applet/app/utils"
  10. "github.com/gin-gonic/gin"
  11. "github.com/jinzhu/copier"
  12. "github.com/tidwall/gjson"
  13. "io/ioutil"
  14. )
  15. // WechatBase 微信支付配置获取
  16. // @Summary 基本配置-微信支付配置获取
  17. // @Tags 基本配置
  18. // @Description 基本配置-微信支付配置获取
  19. // @Accept json
  20. // @Produce json
  21. // @Success 200 {object} md.WechatPay ""
  22. // @Failure 400 {object} md.Response "具体错误"
  23. // @Router /api/v1/communityTeam/agent/wechat/base [GET]
  24. func WechatBase(c *gin.Context) {
  25. user := svc.GetUser(c)
  26. info, _ := db.UserThirdPartyFindByID(svc.MasterDb(c), user.Info.Uid)
  27. var res = md.WechatPay{}
  28. if info != nil {
  29. res.PayWxApiKey = gjson.Get(info.WechatPayInfo, "pay_wx_api_key").String()
  30. res.PayWxMchId = gjson.Get(info.WechatPayInfo, "pay_wx_mch_id").String()
  31. }
  32. e.OutSuc(c, res, nil)
  33. return
  34. }
  35. // WechatBaseSet 微信支付配置保存
  36. // @Summary 基本配置-微信支付配置保存
  37. // @Tags 基本配置
  38. // @Description 基本配置-微信支付配置保存
  39. // @Accept json
  40. // @Produce json
  41. // @Param req body md.WechatPay true "请求参数"
  42. // @Success 200 {string} ""
  43. // @Failure 400 {object} md.Response "具体错误"
  44. // @Router /api/v1/communityTeam/agent/wechat/base/set [POST]
  45. func WechatBaseSet(c *gin.Context) {
  46. var arg md.WechatPay
  47. if err := c.ShouldBindJSON(&arg); err != nil {
  48. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  49. return
  50. }
  51. user := svc.GetUser(c)
  52. info, _ := db.UserThirdPartyFindByID(svc.MasterDb(c), user.Info.Uid)
  53. if info == nil {
  54. info = &model.UserThirdParty{
  55. Uid: user.Info.Uid,
  56. }
  57. svc.MasterDb(c).Insert(info)
  58. }
  59. var data md.WechatPaySave
  60. copier.Copy(&data, &arg)
  61. data.WechatP12ApiclientCert = c.GetString("mid") + "_" + utils.IntToStr(user.Info.Uid) + "_wechat_apiclient_cert.p12"
  62. info.WechatPayInfo = utils.SerializeStr(data)
  63. svc.MasterDb(c).Where("uid=?", info.Uid).Cols("wechat_pay_info").Update(info)
  64. e.OutSuc(c, "success", nil)
  65. return
  66. }
  67. // AlipayBase 支付宝支付配置获取
  68. // @Summary 基本配置-支付宝支付配置获取
  69. // @Tags 基本配置
  70. // @Description 基本配置-支付宝支付配置获取
  71. // @Accept json
  72. // @Produce json
  73. // @Success 200 {object} md.AlipayPay ""
  74. // @Failure 400 {object} md.Response "具体错误"
  75. // @Router /api/v1/communityTeam/agent/alipay/base [GET]
  76. func AlipayBase(c *gin.Context) {
  77. user := svc.GetUser(c)
  78. info, _ := db.UserThirdPartyFindByID(svc.MasterDb(c), user.Info.Uid)
  79. var res = md.AlipayPay{}
  80. if info != nil {
  81. res.PayAliNewAppId = gjson.Get(info.AlipayPayInfo, "pay_ali_new_app_id").String()
  82. res.PayAliNewPrivateKey = gjson.Get(info.AlipayPayInfo, "pay_ali_new_private_key").String()
  83. }
  84. e.OutSuc(c, res, nil)
  85. return
  86. }
  87. // AlipayBaseSet 微信支付配置保存
  88. // @Summary 基本配置-微信支付配置保存
  89. // @Tags 基本配置
  90. // @Description 基本配置-微信支付配置保存
  91. // @Accept json
  92. // @Produce json
  93. // @Param req body md.AlipayPay true "请求参数"
  94. // @Success 200 {string} ""
  95. // @Failure 400 {object} md.Response "具体错误"
  96. // @Router /api/v1/communityTeam/agent/alipay/base/set [POST]
  97. func AlipayBaseSet(c *gin.Context) {
  98. var arg md.AlipayPay
  99. if err := c.ShouldBindJSON(&arg); err != nil {
  100. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  101. return
  102. }
  103. user := svc.GetUser(c)
  104. info, _ := db.UserThirdPartyFindByID(svc.MasterDb(c), user.Info.Uid)
  105. if info == nil {
  106. info = &model.UserThirdParty{
  107. Uid: user.Info.Uid,
  108. }
  109. svc.MasterDb(c).Insert(info)
  110. }
  111. var data md.AlipayPaySet
  112. copier.Copy(&data, &arg)
  113. data.PayAliUseType = "1"
  114. data.PayAppCertSn = c.GetString("mid") + "_" + utils.IntToStr(user.Info.Uid) + "_payAliNewAppCertSn.crt"
  115. data.PayAlipayRootCertSn = c.GetString("mid") + "_" + utils.IntToStr(user.Info.Uid) + "_payAliNewAlipayRootCertSn.crt"
  116. data.PayAlipayrsaPublicKey = c.GetString("mid") + "_" + utils.IntToStr(user.Info.Uid) + "_payAliNewAlipayrsaPublicKey.crt"
  117. path := "./static/"
  118. if cfg.Prd {
  119. path = "/etc/zyos-admin/wx_check_file/"
  120. }
  121. PayAliNewAppCertSn, _ := ioutil.ReadFile(path + data.PayAppCertSn) // 读取文件内容
  122. if string(PayAliNewAppCertSn) != "" {
  123. data.PayAliNewAppCertSn = string(PayAliNewAppCertSn)
  124. }
  125. PayAlipayRootCertSn, _ := ioutil.ReadFile(path + data.PayAlipayRootCertSn) // 读取文件内容
  126. if string(PayAlipayRootCertSn) != "" {
  127. data.PayAliNewAlipayRootCertSn = string(PayAlipayRootCertSn)
  128. }
  129. PayAlipayrsaPublicKey, _ := ioutil.ReadFile(path + data.PayAlipayrsaPublicKey) // 读取文件内容
  130. if string(PayAlipayrsaPublicKey) != "" {
  131. data.PayAliNewAlipayrsaPublicKey = string(PayAlipayrsaPublicKey)
  132. }
  133. info.AlipayPayInfo = utils.SerializeStr(data)
  134. svc.MasterDb(c).Where("uid=?", info.Uid).Cols("alipay_pay_info").Update(info)
  135. e.OutSuc(c, "success", nil)
  136. return
  137. }