|
|
package common
import ( "crypto/sha1" "encoding/xml" "fmt" "hudongzhuanjia/controllers" "hudongzhuanjia/libs/filter" "hudongzhuanjia/logger" "hudongzhuanjia/services/pay" "os" "time" )
var Now = time.Now()
type WeChatOauthCtl struct { controllers.BaseCtl }
const token = "hd_oauth"
// 验证服务器资源配置
func (t *WeChatOauthCtl) Oauth() { signature := t.MustGet("signature") timestamp := t.MustGet("timestamp") nonce := t.MustGet("nonce") echoStr := t.MustGet("echostr") tokenStr := fmt.Sprintf("%s%s%s", token, timestamp, nonce) s := fmt.Sprintf("%s", sha1.New().Sum([]byte(tokenStr))) if s == signature { t.OriginResponseWriter.Write([]byte(echoStr)) } t.OriginResponseWriter.Write([]byte("failed")) }
func (t *WeChatOauthCtl) Checkin() { content, _ := t.Get("content") path, _ := os.Getwd() t.JSON(map[string]interface{}{ "success": "你好, tommy黄梓健", "version": Now, "wd": path, "content": filter.Replace(content), }) }
//
//func init() {
// ticker := time.NewTicker(5 * time.Second)
// go func() {
// fmt.Println("循环查询订单数据")
// for range ticker.C {
// pay_service.BatchQuery()
// }
// }()
//
//}
type CallbackParam struct { XMLName xml.Name `xml:"xml"` ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` }
func (t *WeChatOauthCtl) CallbackOrder() { // 搜索支付的order表, 查找到某条记录
logger.Sugar.Infof("%s", t.Request.OriginRequest.RemoteAddr) t.CheckErr(pay_service.CallbackOrder(t.Request.OriginRequest)) param := new(CallbackParam) param.ReturnCode = "SUCCESS" param.ReturnMsg = "OK" xmlRes, _ := xml.Marshal(param) t.XML(xmlRes) }
func (t *WeChatOauthCtl) CallbackRefund() { logger.Sugar.Infof("%s", t.Request.OriginRequest.RemoteAddr) t.CheckErr(pay_service.CallbackRefund(t.Request.OriginRequest)) param := new(CallbackParam) param.ReturnCode = "SUCCESS" param.ReturnMsg = "OK" xmlRes, _ := xml.Marshal(param) t.XML(xmlRes) }
//func (t *WeChatOauthCtl) SendRedPack() {
// user := new(models.User)
// exist, err := models.GetById(user, 234)
// t.CheckErr(err)
// if !exist {
// t.ERROR(fmt.Sprintf("error occur: %s", err), 120)
// }
// res, err := pay_service.SendRedPack("欧轩互动", user.Openid, "测试", "123.207.246.51",
// "测试", "测试", 100, 1, 1, user.Id, 1)
// t.CheckErr(err)
// fmt.Printf("%+v", res)
// t.JSON(map[string]interface{}{
// "result": res,
// })
//}
|