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

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