Rapid development of WeChat public platform using Golang (i): Turn on server configuration

Source: Internet
Author: User
Tags sha1 sha1 encryption
This is a creation in Article, where the information may have evolved or changed.

The development of public platforms, in the end, is worthless, because the purpose of the public platform is to give people, there is no technical threshold, but the process is too much, recorded, hoping to help other people.

Find the Entrance


In the basic configuration menu, you can see the Modify Configuration button (which is really not found in the group).

Fill in the Parameters


If the server has already mapped the address to port 80 via nginx, it can be written like this (token and key have been replaced, of course).

Start rubbing code


In the document, the official wrote: The 3 parameters sorted in dictionary order, at first I was crazy, and later found that the language version of the sort ... Let's get to the next.

We add a route, this address is the URL that fills in the server configuration
Then add the Wxconnect.go file in the controllers

 PackageControllersImport("Github.com/astaxie/beego"    "Strings"    "Sort"    "CRYPTO/SHA1"    "IO"    "FMT")typeWxconnectcontrollerstruct{Beego. Controller}ConstToken ="Dswq1322s1dfsf31s2af321231rew"func(c *wxconnectcontroller) Get () {//Access Verification This is the first time the server will send a request after filling in the URL.    //c.ctx.request.url-------------wx_connect?signature=038d75ed5485b9881a01b3b93e85f9fff28ea739&echostr= 5756456183388806654&timestamp=1476173150&nonce=1093541731    //Developer submits information (including URL, Token), the server sends an HTTP GET request to the completed URL,    //get request carries four parameters: signature, timestamp, nonce and echostr. The public service program should be authenticated as requiredTimestamp, Nonce,signaturein: = C.getstring ("Timestamp"), C.getstring ("Nonce"), C.getstring ("Signature") Signaturegen: = Makesignature (timestamp, nonce)//The string obtained after encryption is compared with signature, if consistent, indicating that the request originated from    ifSignaturegen! = Signaturein {fmt. Printf ("Signaturegen! = Signaturein signaturegen=%s,signaturein=%s\n", Signaturegen, Signaturein) c.ctx.writestring ("")    }Else{//If the request is from, returns the contents of the ECHOSTR parameter as it is completed, the access verification takes effect and the developer configuration submission succeeds. ECHOSTR: = c.getstring ("Echostr") c.ctx.writestring (ECHOSTR)}}funcMakesignature (timestamp, noncestring)string{//1. Dictionary ordering of the three parameters of Plat_token, timestamp and nonceSL: = []string{Token, timestamp, nonce} sort. Strings (SL)//2. Concatenation of three parameter strings into a single string for SHA1 encryptionS: = SHA1. New () Io. WriteString (S, strings. Join (SL,""))returnFmt. Sprintf ("%x", S.sum (Nil))}

Re-run the project, click on the Settings page of the Submit button, should be able to display through, please carefully proofread parameters, copy and paste good.
At this point, the public platform has opened the door to you (remember to click the Enable button, otherwise the light verification through no eggs).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.