SysPublicController.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package partial
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
  6. "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
  7. "git.qianqiusoft.com/qianqiusoft/light-apiengine/third/alipay"
  8. "git.qianqiusoft.com/qianqiusoft/light-apiengine/third/wx"
  9. "github.com/silenceper/wechat/pay"
  10. "io/ioutil"
  11. //sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
  12. //sysutils "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
  13. //"git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
  14. //__import_packages__
  15. )
  16. // _WxEcho
  17. // @Title _WxEcho
  18. // @Description 微信echo
  19. // @Success 200 {object} Account
  20. // @Failure 403 :id is empty
  21. func SysPublic_WxEcho(c *entitys.CtrlContext) {
  22. echostr := c.Ctx.DefaultQuery("echostr","")
  23. fmt.Println("echostr:"+echostr)
  24. c.Ctx.String(200, echostr)
  25. }
  26. // _WxpayCallback
  27. // @Title _WxpayCallback
  28. // @Description 微信支付回调
  29. // @Success 200 {object} Account
  30. // @Failure 403 :id is empty
  31. func SysPublic_WxpayCallback(c *entitys.CtrlContext) {
  32. r := wx.CallWxPayCallbackHandler(c)
  33. if r.Code != 200{
  34. c.Ctx.JSON(500, r)
  35. }else{
  36. res := pay.NotifyResponse{}
  37. res.ReturnCode = "SUCCESS"
  38. res.ReturnMsg = "OK"
  39. c.Ctx.XML(200,&res)
  40. }
  41. }
  42. // _WxoauthParams
  43. // @Title _WxoauthParams
  44. // @Description 获取微信oauth配置
  45. // @Success 200 {object} Account
  46. // @Failure 403 :id is empty
  47. func SysPublic_WxoauthParams(c *entitys.CtrlContext) {
  48. contentBody, err := ioutil.ReadAll(c.Ctx.Request.Body)
  49. if err != nil{
  50. fmt.Println("读取body错误", err.Error())
  51. c.Ctx.JSON(500, models.SysReturn{500, err.Error(), ""})
  52. return
  53. }
  54. bmap := make(map[string]string)
  55. err = json.Unmarshal(contentBody, &bmap)
  56. if err != nil{
  57. fmt.Println("Unmarshal错误", err.Error())
  58. c.Ctx.JSON(500, models.SysReturn{500, err.Error(), ""})
  59. return
  60. }
  61. param, err := wx.GetOAuthParams(bmap)
  62. if err != nil{
  63. c.Ctx.JSON(500, models.SysReturn{500, "", ""})
  64. }else{
  65. c.Ctx.JSON(200, models.SysReturn{200, "", param})
  66. }
  67. }
  68. // _WxLogin
  69. // @Title _WxLogin
  70. // @Description 获取微信oauth配置
  71. // @Param body false "微信登录参数,必须包含code字段(微信临时令牌)"
  72. // @Success 200 {object} Account
  73. // @Failure 403 :id is empty
  74. func SysPublic_WxLogin(c *entitys.CtrlContext) {
  75. body, err := ioutil.ReadAll(c.Ctx.Request.Body)
  76. if err != nil{
  77. fmt.Println("SysPublic_WxLogin 读取请求数据错误", err.Error())
  78. c.Ctx.JSON(200, models.SysReturn{500, err.Error(), ""})
  79. return
  80. }
  81. params := make(map[string]interface{})
  82. err = json.Unmarshal(body, &params)
  83. if err != nil{
  84. fmt.Println("SysPublic_WxLogin unmarshal err", err.Error())
  85. c.Ctx.JSON(200, models.SysReturn{500, err.Error(), ""})
  86. return
  87. }
  88. code := ""
  89. var v interface{} = nil
  90. ok := false
  91. if v, ok = params["code"]; !ok{
  92. fmt.Println("SysPublic_WxLogin 不存在临时令牌code字段")
  93. c.Ctx.JSON(200, models.SysReturn{500, "不存在临时令牌code字段", ""})
  94. return
  95. }
  96. if code, ok = v.(string); !ok{
  97. fmt.Println("临时令牌code字段不能转换为string")
  98. c.Ctx.JSON(200, models.SysReturn{500, "临时令牌code字段不能转换为string", ""})
  99. return
  100. }
  101. if code == ""{
  102. fmt.Println("临时令牌code为空")
  103. c.Ctx.JSON(200, models.SysReturn{500, "临时令牌code为空", ""})
  104. return
  105. }
  106. // 获取微信信息
  107. userInfo, err := wx.GetUserInfoByCode(code)
  108. if err != nil {
  109. fmt.Println("wx.GetUserInfoByCode 错误", err.Error())
  110. c.Ctx.JSON(200, models.SysReturn{500, err.Error(), nil})
  111. return
  112. }
  113. ret := wx.CallWxLoginCallbackHandler(c, body, userInfo)
  114. c.Ctx.JSON(200, ret)
  115. }
  116. // _WxjssdkParams
  117. // @Title _WxjssdkParams
  118. // @Description 获取微信jssdk配置
  119. // @Success 200 {object} Account
  120. // @Failure 403 :id is empty
  121. func SysPublic_WxjssdkParams(c *entitys.CtrlContext) {
  122. url := c.Ctx.DefaultQuery("url", "")
  123. if url == ""{
  124. c.Ctx.JSON(200, models.SysReturn{500, "参数rul为空", ""})
  125. return
  126. }
  127. config, err := wx.GetJSSDKRarams(url)
  128. if err != nil{
  129. c.Ctx.JSON(200, models.SysReturn{500, err.Error(), ""})
  130. }else{
  131. c.Ctx.JSON(200, models.SysReturn{200, "", config})
  132. }
  133. }
  134. // _AlipayCallback
  135. // @Title _AlipayCallback
  136. // @Description 支付宝支付回调
  137. // @Success 200 {object} Account
  138. // @Failure 403 :id is empty
  139. func SysPublic_AlipayCallback(c *entitys.CtrlContext) {
  140. alipay.CallWxPayCallbackHandler(c)
  141. }
  142. func __none_func_sys_public__(params ... interface{}) bool{
  143. return true
  144. }