互动
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.

112 lines
2.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package common
  2. import (
  3. "crypto/sha1"
  4. "encoding/xml"
  5. "fmt"
  6. "go.uber.org/atomic"
  7. "hudongzhuanjia/controllers"
  8. "hudongzhuanjia/libs/filter"
  9. "os"
  10. "time"
  11. )
  12. var Now = time.Now()
  13. type WeChatOauthCtl struct {
  14. controllers.BaseCtl
  15. }
  16. const token = "hd_oauth"
  17. // 验证服务器资源配置
  18. func (t *WeChatOauthCtl) Oauth() {
  19. signature := t.MustGet("signature")
  20. timestamp := t.MustGet("timestamp")
  21. nonce := t.MustGet("nonce")
  22. echoStr := t.MustGet("echostr")
  23. tokenStr := fmt.Sprintf("%s%s%s", token, timestamp, nonce)
  24. s := fmt.Sprintf("%s", sha1.New().Sum([]byte(tokenStr)))
  25. if s == signature {
  26. t.OriginResponseWriter.Write([]byte(echoStr))
  27. }
  28. t.OriginResponseWriter.Write([]byte("failed"))
  29. }
  30. func (t *WeChatOauthCtl) Checkin() {
  31. content, _ := t.Get("content")
  32. path, _ := os.Getwd()
  33. t.JSON(map[string]interface{}{
  34. "success": "你好, tommy黄梓健",
  35. "version": Now,
  36. "wd": path,
  37. "content": filter.Replace(content),
  38. })
  39. }
  40. //
  41. //func init() {
  42. // ticker := time.NewTicker(5 * time.Second)
  43. // go func() {
  44. // fmt.Println("循环查询订单数据")
  45. // for range ticker.C {
  46. // pay_service.BatchQuery()
  47. // }
  48. // }()
  49. //
  50. //}
  51. type CDATA struct {
  52. Text string `xml:",cdata"`
  53. }
  54. type CallbackParam struct {
  55. XMLName xml.Name `xml:"xml"`
  56. ReturnCode CDATA `xml:"return_code"`
  57. ReturnMsg CDATA `xml:"return_msg"`
  58. }
  59. var counter = new(atomic.Int64)
  60. func (t *WeChatOauthCtl) CallbackOrder() {
  61. counter.Add(1)
  62. // 搜索支付的order表, 查找到某条记录
  63. //t.CheckErr(pay_service.NotifyOrder(t.Request.OriginRequest))
  64. param := new(CallbackParam)
  65. param.ReturnCode = CDATA{Text: "SUCCESS"}
  66. param.ReturnMsg = CDATA{Text: "OK"}
  67. xmlRes, _ := xml.Marshal(param)
  68. if t.Request.OriginRequest.Method == "GET" {
  69. t.JSON(map[string]interface{}{
  70. "counter": counter.Load(),
  71. "time": time.Now(),
  72. })
  73. }
  74. t.XML(xmlRes)
  75. }
  76. //func (t *WeChatOauthCtl) CallbackRefund() {
  77. // logger.Sugar.Infof("%s", t.Request.OriginRequest.RemoteAddr)
  78. // //t.CheckErr(pay_service.NotifyRefund(t.Request.OriginRequest))
  79. // param := new(CallbackParam)
  80. // param.ReturnCode = "SUCCESS"
  81. // param.ReturnMsg = "OK"
  82. // xmlRes, _ := xml.Marshal(param)
  83. // t.XML(xmlRes)
  84. //}
  85. //func (t *WeChatOauthCtl) SendRedPack() {
  86. // user := new(models.User)
  87. // exist, err := models.GetById(user, 234)
  88. // t.CheckErr(err)
  89. // if !exist {
  90. // t.ERROR(fmt.Sprintf("error occur: %s", err), 120)
  91. // }
  92. // res, err := pay_service.SendRedPack("欧轩互动", user.Openid, "测试", "123.207.246.51",
  93. // "测试", "测试", 100, 1, 1, user.Id, 1)
  94. // t.CheckErr(err)
  95. // fmt.Printf("%+v", res)
  96. // t.JSON(map[string]interface{}{
  97. // "result": res,
  98. // })
  99. //}