Micro-channel public number + h5 project development

Demand: micro channel number is the public entrance, h5 page common user business operations, the user information is completely dependent on public number;

Solution: Create a public number - "No user public concern -" Silent authorized to h5 page - "h5 page for user information -" user business operations on h5 page;

Preparation: a public number (must be a required certification, certification requires hard conditions, but can only use test account, place a test account pit, will be mentioned below), you can access the domain name server port 80 a (domain name and servers are well out cheaper, but the record needs to access the domain name, but can only find the tools within the network penetration, I use natapp, start with the free version, but the domain name is very unstable, once every change need to change the code to change the settings, simply buy a vpi tunnel 9 dollars a month on natapp, and then bought a domain name at the top, three dollars a year, with a fairly stable in the afternoon, more than enough to do development a)

Tools: VS + HBuilderX + Mysql + micro channel development tools

step:

1 .net Create A webapi provides interface functions and the user authentication information acquiring specific service interface 2

2 MySQL database storing user information and traffic data

After 3 uni-app create h5 page

Nothing esoteric code share part of the code page authorization

onLoad() {
            var appId = 'xxx';
            var reg = new RegExp("(^|&)" + "code" + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            var code = "";
            if (r != null)
                code = unescape(r[2]);

            if (code == null || code == "" ) { 
                Window.location.href = " https://open.weixin.qq.com/connect/oauth2/authorize?appid= " + for appId + " & the redirect_uri = " + 
                    the encodeURIComponent ( " XXX " ) +
                     " & response_type = & scope = & snsapi_userinfo code State = # wechat_redirect. 1 " ; // page authorization 
            } the else { 
          // after obtaining the user authorization information according to the code returned uni.request ({ URL:
' XXXX ' , header: { 'type-Content ' : ' file application / X-WWW-form-urlencoded ' // custom request header information }, Method: ' the POST ' , Data: { Code: code }, Success: RES => { the this .Data = RES .data; }, Fail: Fail => {}, Complete: () => {} }); } }

Local stepped pit:

a js cross-domain problems, many solutions online, I simply deploy web sites and api site to the next site, one of which is arranged site, another application arranged at the site;

b. If the user is not concerned about the public number, the system prompts the public to be concerned about the number, error code 10006. Right now the meaning is not concerned about not play. Most said that the cause of the problem online tests reasons account;

c I started thinking there wrong authorized, in accordance with the demand, because the user is operating under the premise of public concern number, so I just silently through authorized users can get more information by public users get the interface number of openId, beginning that necessarily non-silent license. The case of non-silent authorized users are generally not concerned about the public number will be used.

D had no contact before the development of public numbers, just started to discuss this thing with a few colleagues, they actually are sure that will change every time openid / or to refocus the public after the number changes, and today we proved them wrong. Since then I changed out openid no way to identify the user, and made Huang Huang. It seems practice makes perfect, and his uncertain technology must not say very determined way, of people have been not good, remember.

Guess you like

Origin www.cnblogs.com/shawn-he/p/11247853.html