加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

使用Golang开发微信公众平台----接入验证

发布时间:2020-12-16 18:43:06 所属栏目:大数据 来源:网络整理
导读:第一步:填写服务器配置 1. URL,http://开头,支持8080端口 2. Token,令牌 3. EncodingAESKey,随机生成 第二步:验证服务器地址有效性 pre style="margin-top: 0px; margin-bottom: 0px;"span style=" font-weight:600; color:#000080;"import/spanspan s

第一步:填写服务器配置
1. URL,http://开头,支持8080端口
2. Token,令牌

3. EncodingAESKey,随机生成


第二步:验证服务器地址有效性

 <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"
)
const (
token = "******"
)
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") //随机字符串
                                                                                                                           //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>)
 
}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读