当前位置: 首页 > news >正文

好网站你知道网络推广外包业务怎么样

好网站你知道,网络推广外包业务怎么样,签名图片在线制作,wordpress弹出公告总览 引导用户进入授权页面同意授权,获取code通过code换取网页授权access_token(与基础支持中的access_token不同)如果需要,开发者可以刷新网页授权access_token,避免过期(一般不需要)通过网页…

总览

  1. 引导用户进入授权页面同意授权,获取code
  2. 通过code换取网页授权access_token(与基础支持中的access_token不同)
  3. 如果需要,开发者可以刷新网页授权access_token,避免过期(一般不需要)
  4. 通过网页授权access_token和openid获取用户基本信息(支持UnionID机制)

获取code

解释:让用户跳转到拼接后的指定地址,进行授权获取code,然后重定向到redirect_uri,重定向后的地址带有code和state参数

拼接地址:https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect,其中appid和redirect_uri需要替换,且redirect_uri需要encodeURI处理,state为可选值用于用户自定义传参。

通过code换取access_token和用户信息

这里只写Java示例,且使用weixin-java-mp依赖

引入以下依赖

<dependency><groupId>com.github.binarywang</groupId><artifactId>weixin-java-mp</artifactId><version>4.5.0</version>
</dependency>

在application.yml中添加如下参数

# 自定义微信相关配置信息
wx:mp:# 微信公众号的appidappId: wxajhlksfnjls777777# 信公众号的app secretsecret: sds56dg4fd5sd54s5555555

创建WxMpProperties如下

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@Data
@ConfigurationProperties(prefix = "wx.mp")
public class WxMpProperties {/*** 设置微信公众号的appid*/private String appId;/*** 设置微信公众号的app secret*/private String secret;
}

创建WxMpConfiguration如下

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class WxMpConfiguration {@Autowiredprivate WxMpProperties wxMpProperties;/*** 微信客户端配置存储*/@Beanpublic WxMpConfigStorage wxMpConfigStorage() {WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();// 设置微信公众号appIdconfigStorage.setAppId(wxMpProperties.getAppId());// 设置微信公众号appSecretconfigStorage.setSecret(wxMpProperties.getSecret());return configStorage;}/*** WxMpService多个实现类 声明一个实例*/@Beanpublic WxMpService wxMpService() {WxMpService wxMpService = new WxMpServiceImpl();wxMpService.setWxMpConfigStorage(wxMpConfigStorage());return wxMpService;}
}

然后在Controller中引入WxMpService

@RestController
public class LoginController {@Autowiredprivate WxMpService wxMpService;@PostMapping("/wx/login")public SysAjaxResult login(@RequestBody Map<String, String> params) {String code = MapUtils.getString(params, "code");if (StringUtils.isBlank(code)) {return SysAjaxResult.error("code不能为空");}try {// 获取accessToken,获取用户信息(据官方文档,下面两个接口调用频率为每分钟5万次)WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);// 通过openid校验有没有当前用户,没有则新增String openid = userInfo.getOpenid();return AjaxResult.success();} catch (WxErrorException e) {e.printStackTrace();}return AjaxResult.error();}
}

时效

接口名频率限制
通过 code 换取 access_token5 万/分钟
获取用户基本信息5 万/分钟
刷新 access_token10 万/分钟
http://www.khdw.cn/news/9142.html

相关文章:

  • 做网站的属于什么专业百度导航下载安装手机导航
  • 如何查询注册过的网站360指数
  • 闸北区网站建设网页制网络宣传推广方案
  • 鄱阳有做百度网站的优化排名
  • dz可以做门户网站吗网站推广开户
  • 那个有那种网站百度推广有哪些售后服务
  • 经销商怎么做网站企业快速建站
  • 中文旅游网站html模板seo外包公司哪家好
  • 网站设计与建设word设计理念百度域名注册
  • 方城微网站建设深圳网络seo推广
  • 响应式 购物网站模板做一套二级域名网站怎么做
  • 做网站 服务器价格教育培训网站
  • seo优化方法网站快速排名推广渠道seo优化的主要内容
  • 服务器搭建网站数据库网络服务运营商
  • 郑州网站开发公司西安seo优化培训
  • 微信管理系统在哪seo全网营销的方式
  • 网络代理加盟平台新网站排名优化怎么做
  • wordpress手机端网站模板下载失败seo关键词优化排名哪家好
  • 企业所得税25%怎么计算seo排名怎么优化软件
  • 佛山专业网站制作设计如何宣传推广自己的产品
  • 唐山模板建站定制网站企业网站大全
  • 常州做网站需要多少钱百度登录页
  • 单机无网络游戏seo页面链接优化
  • wordpress导航仿制seo职位招聘
  • 找做cad彩拼的网站seo推广哪家好
  • 高端制作网站服务seo关键词优化怎么收费
  • 厦门双瑞高磁网站是谁做的登录百度账号注册
  • 重庆开县网站建设公司百度推广找谁
  • 专门做网站开发的公司龙华线上推广
  • 如何查看网站做没做竞价app排名优化公司