1.獲取code
var jumpUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?' var params = { appid: '', // 公眾號appid redirect_uri: 'http://woejfoa.com/a/s.html', //回調地址,域名配置同一地址 定位到目錄 response_type: 'code', scope: 'snsapi_userinfo',// 需要用戶確認登錄 state: 'STATE' } jumpUrl += $.param(params) + '#wechat_redirect' location.href = jumpUrl // 獲取code跳轉到回調地址
在回調地址頁面截取url獲得code
2.通過接口把code傳給后台服務器,后台通過code獲得access_token openid 等用戶信息返回給前端就可以了