微信授权 & 扫码登录 - 快速入门(手动 & 第三方SDK)(一)

简介: 微信授权 & 扫码登录 - 快速入门(手动 & 第三方SDK)(一)

image.png


手动方式

package com.imooc.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/weixin")
@Slf4j
public class WeixinController {
    @GetMapping("/auth")
    public void auth(@RequestParam("code") String code) {
        log.info("进入auth方法。。。");
        log.info("code={}", code);
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxd898fcb01713c658&secret=29d8a650db31472aa87800e3b0d739f2&code=" + code + "&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        String response = restTemplate.getForObject(url, String.class);
        log.info("response={}", response);
    }
}


第三方SDK

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


wechat:
  # 公众账号, 授权
  mpAppId: wxd898fcb01713c658
  mpAppSecret:
  # 开放平台,  卖家扫码登录用
  openAppId: wx6ad144e54af67d87
  openAppSecret: 91a2ff6d38a2bbccfb7e9xxxxxx
  # 支付/商户号
  mchId: 1483469312
  mchKey: 06C56A89949D617xxxxxxxxxxx
  # 发起支付不需要证书, 退款需要
  keyPath:
  notifyUrl: http://sell.natapp4.cc/sell/pay/notify
  templateId:
    orderStatus: e-Cqq67QxD6YNI41iRiqawEYdFavW_7pc7LyEMb-yeQ
projectUrl:
  wechatMpAuthorize: http://lsx888.natapp1.cc
  wechatOpenAuthorize: http://lsx888.natapp1.cc
  sell: http://lsx888.natapp1.cc
package com.imooc.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@ConfigurationProperties(prefix = "project-url")
@Component
public class ProjectUrlConfig {
    /**
     * 微信公众平台授权url
     */
    public String wechatMpAuthorize;
    /**
     * 微信开放平台授权url
     */
    public String wechatOpenAuthorize;
    /**
     * 点餐系统
     */
    public String sell;
}
目录
相关文章
|
17天前
|
开发工具
微信客服系统开发SDK使用教程- 拉取当前微信个人号列表请求(立即)
微信客服系统开发SDK使用教程- 拉取当前微信个人号列表请求(立即)
|
6天前
|
PHP 开发工具
tp5+微信公众号服务器配置时使用官方sdk还是token验证失败
tp5+微信公众号服务器配置时使用官方sdk还是token验证失败
9 0
|
11天前
|
API 开发工具
企业微信SDK接口API调用-通过手机号或微信好友添加客户
企业微信SDK接口API调用-通过手机号或微信好友添加客户
|
11天前
|
API 开发工具
企业微信SDK接口API调用-触发推送企业微信微信好友
企业微信SDK接口API调用-触发推送企业微信微信好友
|
17天前
|
Java API 开发工具
企业微信api,企业微信sdk接口java调用源码
企业微信api,企业微信sdk接口java调用源码
|
17天前
|
API 开发工具
企业微信api接口,企业微信sdk
企业微信api接口,企业微信sdk
|
17天前
|
开发工具
云控微信开发SDK使用教程--手机微信朋友圈图片上传服务端
云控微信开发SDK使用教程--手机微信朋友圈图片上传服务端
|
18天前
|
XML 开发工具 iOS开发
替代微信ipad协议的sdk方案分享
替代微信ipad协议的sdk方案分享
|
4天前
|
小程序 开发者
uniapp实战 —— 开发微信小程序的调试技巧
uniapp实战 —— 开发微信小程序的调试技巧
10 1
|
4天前
|
小程序
【微信小程序-原生开发】富文本编辑器 editor 的使用教程
【微信小程序-原生开发】富文本编辑器 editor 的使用教程
14 0
【微信小程序-原生开发】富文本编辑器 editor 的使用教程