[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Micro-channel in order to obtain the user authorization is openId

Micro-channel public number:
https://mp.weixin.qq.com/
micro-channel pay :( only qualified enterprises can apply for micro-channel payment)
https://pay.weixin.qq.com/
micro-channel payment process documentation:
HTTPS: / /pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_4
micro letter public, authorized the document:
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html

Purchase a domain name
if the domain name has been and is filed can ignore this step
the following steps of the method can access the local domain name has been configured for the purchase of test:
URL: https://natapp.cn/login
1: buy a year of tunnel:

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

2: Buy a can support micro-domain authorization letter:

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

3: binding domain just purchased and the local port can access

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

4: Download natapp client, edit the file confing.ini authtoken fill:

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

5: Double-click natapp.exe start natapp

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

6: you can access the application through the local port 80 applenst.natapp4.cc

Micro-letter domain name Configuration
1: micro-channel public account Log: Development - Interface Permissions - Web Services - Web Account - Web authorization to obtain information about users' configuration options, modify the authorization callback domain:

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

2: Download the micro-channel to be certified MP_verify_WKBRuq9wmTSbo3Ep.txt into static directory project

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

3: In order to make micro-channel authentication, temporary access path of the project to remove and restart the project

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

4: Let the micro-channel certification

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

5: Successful certification

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

6: The project path to come back and restart the project

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Functional development
documentation
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the
Dependent instructions
in pom file to add third-party sdk relies

<! - micro-channel authorization dependent ->
<dependency>
<the groupId> com.github.binarywang </ the groupId>
<the artifactId> Weixin-Java-MP </ the artifactId>
<Version> 2.7.0 </ Version>
</ dependency >
code implements
1: configure public number in the configuration file and Secret appid

wechat:
mpAppId: wxXXXXXXXXXXXXXXXXXXX83c0577b
mpAppSecret: b6XXXXXXXXXXXXXXXff886d71
domainUrl: http://applenst.natapp4.cc # micro-channel callback domain name (domain name of Project Access)
2: Create a profile JavaBean
COM \ imooc \ config \ WechatAccountConfig.java

Data
Component
@ConfigurationProperties(prefix = "wechat")
public class WechatAccountConfig {

/*公众号微信授权appid*/
private String mpAppId;

/*公众号微信授权app Secret*/
private String mpAppSecret;

/*微信回调域名*/
private String domainUrl;

}
3: Create authorized micro-channel configuration class
com \ imooc \ config \ WeChatMpConfig.java

package com.imooc.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**

@Controllerbr/>@RequestMapping("/wechat")
@Slf4j
public class WechatController {

/*注解微信授权sdk的业务接口*/
@Autowired
private WxMpService wxMpService;

/*注解微信授权配置javabean*/
@Autowired
private WechatAccountConfig accountConfig;

@GetMapping("/authorize")
public String authorize(@RequestParam("returnUrl") String returnUrl){

    /*url:授权成功后要跳转的路径*/
    String url = accountConfig.getDomainUrl() + "/sell/wechat/userInfo";
    /*进行微信授权,授权成功后会在userinfo方法中得到code,并得到一个微信返回的url 通过这个url可以跳转到上面定义的url*/
    String redirectUrl = wxMpService.oauth2buildAuthorizationUrl(url,WxConsts.OAUTH2_SCOPE_USER_INFO, URLEncoder.encode(returnUrl));
    log.info(redirectUrl);
    /*进行跳转*/
    return "redirect:"+redirectUrl;
}

@GetMapping("/userInfo")
public String userInfo(@RequestParam("code") String code,
                     @RequestParam("state") String returnUrl){
    /*code:授权成功后会返回一个code
    * state:授权成功后的原始参数*/
    WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
    try{
        wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
    }catch (WxErrorException e){
        log.error("微信授权失败");
    }
    /*得到openid*/
    String openId = wxMpOAuth2AccessToken.getOpenId();

    /*跳转到系统*/
    return "redirect:"+ returnUrl + "?openid="+openId;
}

}
5: test micro-channel authorization (mobile access, normal to jump to Baidu)
http://applenst.natapp4.cc/sell/wechat/authorize?returnUrl=http://www.baidu.com

6: Build the project and the FBI
1> configure virtual machines authorized access path:

/opt/code/sell_fe_buyer/config/index.js

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Enter / opt / code / sell_fe_buyer directory rebuild command execution

npm run build

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Copy the file to take effect

cp -r dist/* /opt/data/wwwrot/sell/

2> configure the phone proxy can access computer terminal
to download and install fiddler set
https://www.telerik.com/fiddler

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Iphone mobile terminal configuration:
Settings - Wireless Network - Configure proxy - Manual

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Micro-channel access project: sell.com (domain name nginx configuration, pc's hosts file to perform virtual machine ip):

[6] Swiss ant original share: Micro letter authorizing springboot micro letter ordering the

Guess you like

Origin blog.51cto.com/14735449/2477253