Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 88caffdd
authored
Nov 22, 2022
by
姜鹏凯
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
微信登录授权调整
1 parent
dc85c3b1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
48 deletions
linkwe-mobile/src/api/common.js
linkwe-mobile/src/utils/index.js
linkwe-mobile/src/api/common.js
View file @
88caffd
import
request
from
'@/utils/request'
import
request
from
'@/utils/request'
const
service
=
window
.
lwConfig
.
services
.
wecom
const
service
=
window
.
lwConfig
.
services
.
wecom
const
weChat
=
window
.
lwConfig
.
services
.
weChat
/**
/**
* 获取应用的jsapi_ticket
* 获取应用的jsapi_ticket
...
@@ -17,7 +18,7 @@ export function getAgentTicket (url) {
...
@@ -17,7 +18,7 @@ export function getAgentTicket (url) {
export
function
getWxTicket
(
data
)
{
export
function
getWxTicket
(
data
)
{
return
request
({
return
request
({
url
:
service
+
'/ticket/getWxTicket'
,
url
:
weChat
+
'/ticket/getWxTicket'
,
params
:
{
params
:
{
url
:
data
,
url
:
data
,
},
},
...
...
linkwe-mobile/src/utils/index.js
View file @
88caffd
...
@@ -91,57 +91,36 @@ import { getUserOpenid, getWechatUserInfo, getWxRedirect, wxLogin } from '@/api/
...
@@ -91,57 +91,36 @@ import { getUserOpenid, getWechatUserInfo, getWxRedirect, wxLogin } from '@/api/
// 微信端授权登录
// 微信端授权登录
export
async
function
getWxCode
()
{
export
async
function
getWxCode
()
{
let
userinfo
=
sessionStorage
.
getItem
(
'userinfo'
)
let
userinfo
=
sessionStorage
.
getItem
(
'userinfo'
)
//取缓存中的用户信息
//取缓存中的用户信息
if
(
userinfo
)
{
if
(
userinfo
)
{
try
{
userinfo
=
JSON
.
parse
(
userinfo
)
}
catch
(
error
)
{
// alert(error)
}
return
userinfo
}
//缓存中没有用户信息,进入授权流程
// let appId = 'wxa57479bcd3f15461'
let
appId
=
window
.
lwConfig
.
appId
// 微信公众号id
// let appId = 'wxa57479bcd3f15461' // 公众号appid
let
code
=
getQueryValue
(
'code'
)
//是否存在code
// let query = param2Obj() //
// let { code, appId, secret } = query
let
local
=
window
.
location
.
origin
.
includes
(
'localhost'
)
?
'http://h5.linkwechat.cn/test.html'
:
window
.
location
.
href
if
(
!
code
)
{
//不存在就打开上面的地址进行授权
let
url
=
''
if
(
appId
)
{
url
=
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=
${
appId
}
&redirect_uri=
${
encodeURIComponent
(
local
)}
&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
}
else
{
url
=
(
await
getWxRedirect
()).
data
let
id
=
getQueryValue
(
'appid'
,
url
)
sessionStorage
.
setItem
(
'weAppId'
,
id
)
}
window
.
location
.
href
=
url
// return new Promise(() => { })
// window.location.href =
// `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect`;
}
try
{
try
{
if
(
code
)
{
userinfo
=
JSON
.
parse
(
userinfo
)
let
{
data
:
dataLogin
}
=
await
wxLogin
(
code
)
sessionStorage
.
setItem
(
'token'
,
dataLogin
.
access_token
)
let
{
data
:
dataUser
}
=
await
getWechatUserInfo
()
sessionStorage
.
setItem
(
'userinfo'
,
JSON
.
stringify
(
dataUser
))
return
dataUser
}
}
catch
(
error
)
{
}
catch
(
error
)
{
// alert(JSON.stringify(error))
// alert(error)
return
Promise
.
reject
()
}
return
userinfo
}
let
code
=
getQueryValue
(
'code'
)
//是否存在code
if
(
!
code
)
{
let
url
=
(
await
getWxRedirect
()).
data
let
id
=
getQueryValue
(
'appid'
,
url
)
sessionStorage
.
setItem
(
'weAppId'
,
id
)
window
.
location
.
href
=
url
}
try
{
if
(
code
)
{
let
{
data
:
dataLogin
}
=
await
wxLogin
(
code
)
sessionStorage
.
setItem
(
'token'
,
dataLogin
.
access_token
)
let
{
data
:
dataUser
}
=
await
getWechatUserInfo
()
sessionStorage
.
setItem
(
'userinfo'
,
JSON
.
stringify
(
dataUser
))
return
dataUser
}
}
}
catch
(
error
)
{
return
Promise
.
reject
()
}
}
}
// 日期时间格式化
// 日期时间格式化
export
function
dateFormat
(
dateString
,
fmt
=
'yyyy-MM-dd hh:mm:ss'
)
{
export
function
dateFormat
(
dateString
,
fmt
=
'yyyy-MM-dd hh:mm:ss'
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment