第一步:填写服务器配置
1. URL,http://开头,支持8080端口
2. Token,令牌
第二步:验证服务器地址有效性
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" font-weight:600; color:#000080;">import</span><span style=" color:#c0c0c0;"> </span>(
"crypto/sha1"
"encoding/json"
"encoding/xml"
"fmt"
"github.com/astaxie/beego"
"io"
"io/IoUtil"
"net/http"
"sort"
"strings"
"time"
)Get(){ signature := this.Ctx.Request.Form.Get("signature") //微信加密签名timestamp := this.Ctx.Request.Form.Get("timestamp") //时间戳nonce := this.Ctx.Request.Form.Get("nonce") //随机数echostr := this.Ctx.Request.Form.Get("echostr") //随机字符串const (token = "******")
//token 令牌 slice := []string{token, timestamp, nonce}
sort.Strings(slice)
str := sha1.New()
io.WriteString(str, strings.Join(slice, ""))
tsignature := fmt.Sprintf("%x", str.Sum(nil))
if tsignature == signature {
fmt.Fprintf(this.Ctx.ResponseWriter, echostr)
fmt.Println("接入请求成功!!!!!!")
} else {<pre style="margin-top: 0px; margin-bottom: 0px;"> fmt.Println(<span style="color: rgb(0,128,0);">"接入验证失败!!!!!!"</span>)
}} 原文链接:https://www.f2er.com/go/190414.html