Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
Y
ybf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xulili
ybf
Commits
0af9e069
Commit
0af9e069
authored
Jan 15, 2020
by
Z
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
Z: Dot: Wx API can get Token.
parent
b4962c23
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
302 additions
and
12 deletions
+302
-12
App.vue
ybf_wx/src/App.vue
+10
-0
active.js
ybf_wx/src/api/test/active.js
+1
-1
main.js
ybf_wx/src/api/test/main.js
+1
-1
aCommon.js
ybf_wx/src/utils/aCommon.js
+230
-0
aRequest.js
ybf_wx/src/utils/aRequest.js
+11
-5
aWxRequest.js
ybf_wx/src/utils/aWxRequest.js
+44
-0
bRequestEa.js
ybf_wx/src/utils/bRequestEa.js
+5
-5
bRequestEaPost.js
ybf_wx/src/utils/bRequestEaPost.js
+0
-0
No files found.
ybf_wx/src/App.vue
View file @
0af9e069
...
@@ -4,6 +4,16 @@
...
@@ -4,6 +4,16 @@
</div>
</div>
</
template
>
</
template
>
<
script
>
import
{
getXToken
}
from
'./utils/aCommon'
getXToken
()
export
default
{
name
:
'App'
}
</
script
>
<
style
lang=
"scss"
>
<
style
lang=
"scss"
>
/*@import '~@/assets/style/public.scss';*/
/*@import '~@/assets/style/public.scss';*/
</
style
>
</
style
>
ybf_wx/src/api/test/active.js
View file @
0af9e069
import
request
from
'@/utils/
r
equestEa'
import
request
from
'@/utils/
bR
equestEa'
// 案例
// 案例
export
function
getCaseList
(
data
)
{
export
function
getCaseList
(
data
)
{
...
...
ybf_wx/src/api/test/main.js
View file @
0af9e069
import
request
from
'@/utils/
r
equestEa'
import
request
from
'@/utils/
bR
equestEa'
export
function
ApiTestGet
()
{
export
function
ApiTestGet
()
{
return
request
({
return
request
({
...
...
ybf_wx/src/utils/aCommon.js
0 → 100644
View file @
0af9e069
import
Vue
from
'vue'
import
{
wxRequest
}
from
'./aWxRequest'
import
qs
from
'qs'
import
router
from
'../router'
// Z-BasicInfo
let
INFO
=
{
corpId
:
'wwd1cdbca7b8b2b6c4'
,
agentId
:
'1000015'
,
}
async
function
getXToken
()
{
let
postData
=
{
corpId
:
INFO
.
corpId
,
agentId
:
INFO
.
agentId
,
}
await
wxRequest
(
'/workWx/common/getToken'
,
qs
.
stringify
(
postData
)).
then
(
res
=>
{
if
(
res
.
result
==
'success'
)
{
sessionStorage
.
setItem
(
'XToken'
,
res
.
data
)
}
else
{
this
.
$message
({
message
:
res
.
errorMsg
,
type
:
'error'
})
}
}).
catch
(
err
=>
{
console
.
log
(
'!==>getXToken: err:'
,
err
)
})
}
function
isIosOrAndroid
()
{
let
u
=
navigator
.
userAgent
;
let
isAndroid
=
u
.
indexOf
(
'Android'
)
>
-
1
||
u
.
indexOf
(
'Adr'
)
>
-
1
// android终端
let
isiOS
=
!!
u
.
match
(
/
\(
i
[^
;
]
+;
(
U;
)?
CPU.+Mac OS X/
)
// ios终端
let
isStr
=
''
if
(
isAndroid
)
{
isStr
=
'android'
}
if
(
isiOS
)
{
isStr
=
'ios'
}
return
isStr
}
Vue
.
prototype
.
getAgentAuth
=
function
()
{
let
postData
=
{
// businessId: sessionStorage.getItem('businessId'),
// pageUrl: encodeURIComponent(this.isIosOrAndroid() === 'android' ? location.href.split('#')[0] : window.initUrl)
pageUrl
:
encodeURIComponent
(
location
.
href
.
split
(
'#'
)[
0
])
}
let
header
=
{
token
:
sessionStorage
.
getItem
(
'XToken'
),
corpId
:
INFO
.
corpId
,
agentId
:
INFO
.
agentId
,
}
wxRequest
(
'/workWx/auth/base/getJsSdkSignature'
,
qs
.
stringify
(
postData
),
header
).
then
(
res
=>
{
if
(
res
.
result
==
'success'
)
{
let
config
=
res
.
data
wx
.
config
({
beta
:
true
,
debug
:
false
,
//调试的时候可以开启
appId
:
config
.
jsApiSignature
.
appId
,
// 必填,公众号的唯一标识
timestamp
:
config
.
jsApiSignature
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
config
.
jsApiSignature
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
config
.
jsApiSignature
.
signature
,
// 必填,签名
// 根据自己的需求,填写 jsapilist 内容
jsApiList
:
[
'agentConfig'
]
})
wx
.
ready
(
function
()
{
// JS-SDK配置信息验证失败时会进入此方法
wx
.
error
(
function
(
res
)
{
alert
(
"JS-SDK配置信息验证失败
\
r
\n
"
+
JSON
.
stringify
(
res
));
})
// 配置成功后验证API接口在当前客户端是否支持:判断当前客户端版本是否支持指定JS接口
wx
.
checkJsApi
({
jsApiList
:
[
'agentConfig'
,
'sendChatMessage'
],
success
:
function
(
res
)
{
if
(
res
.
errMsg
!=
"checkJsApi:ok"
)
{
alert
(
"JS-SDK接口检测失败:"
+
JSON
.
stringify
(
res
));
return
false
;
}
else
{
wxRequest
(
'/workWx/auth/base/getAgentJsSdkSignature'
,
qs
.
stringify
(
data
),
header
).
then
(
res
=>
{
// alert('getAgentJsSdkSignature:ok')
if
(
res
.
result
==
'success'
)
{
let
agentConfig
=
res
.
data
wx
.
agentConfig
({
corpid
:
agentConfig
.
agentJsApiSignature
.
appId
,
// 必填,企业微信的corpid,必须与当前登录的企业一致
agentid
:
agentConfig
.
agentId
,
// 必填,企业微信的应用id
timestamp
:
agentConfig
.
agentJsApiSignature
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
agentConfig
.
agentJsApiSignature
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
agentConfig
.
agentJsApiSignature
.
signature
,
// 必填,签名,agentConfig所以为应用签名
jsApiList
:
[
'sendChatMessage'
],
//必填
success
:
function
(
res
)
{
// alert('agentConfig:ok')
// router.push(to)
// 回调
//1、发起申请申请时后,审批状态发生变化时
//2、发起申请申请时后,在“审批中”状态,有任意审批人进行审批操作时
// alert('wx.agentConfig 回调'+res.errMsg);
},
fail
:
function
(
res
)
{
// alert('回调失败:'+res.errMsg)
if
(
res
.
errMsg
.
indexOf
(
'is not a function'
)
>
-
1
)
{
alert
(
'<i class="weui-icon-warn">版本过低请升级</i>'
)
}
}
})
}
})
}
}
})
})
}
else
{
this
.
$message
({
type
:
'error'
,
message
:
res
.
errorMsg
})
}
}).
catch
(
err
=>
{
console
.
log
(
err
,
'err'
)
})
}
function
configWx
(
to
)
{
let
postData
=
{
// businessId: sessionStorage.getItem('businessId'),
// pageUrl: encodeURIComponent(this.isIosOrAndroid() === 'android' ? location.href.split('#')[0] : window.initUrl)
pageUrl
:
encodeURIComponent
(
location
.
href
.
split
(
'#'
)[
0
])
}
let
header
=
{
token
:
sessionStorage
.
getItem
(
'XToken'
),
corpId
:
INFO
.
corpId
,
agentId
:
INFO
.
agentId
,
}
wxRequest
(
'/workWx/auth/base/getJsSdkSignature'
,
qs
.
stringify
(
postData
),
header
).
then
(
res
=>
{
if
(
res
.
result
==
'success'
)
{
let
config
=
res
.
data
wx
.
config
({
beta
:
true
,
debug
:
true
,
//调试的时候可以开启
appId
:
config
.
jsApiSignature
.
appId
,
// 必填,公众号的唯一标识
timestamp
:
config
.
jsApiSignature
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
config
.
jsApiSignature
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
config
.
jsApiSignature
.
signature
,
// 必填,签名
// 根据自己的需求,填写 jsapilist 内容
jsApiList
:
[
'agentConfig'
]
})
wx
.
ready
(
function
()
{
// JS-SDK配置信息验证失败时会进入此方法
wx
.
error
(
function
(
res
)
{
alert
(
"JS-SDK配置信息验证失败
\
r
\n
"
+
JSON
.
stringify
(
res
));
})
// 配置成功后验证API接口在当前客户端是否支持:判断当前客户端版本是否支持指定JS接口
wx
.
checkJsApi
({
jsApiList
:
[
'agentConfig'
,
'getCurExternalContact'
],
success
:
function
(
res
)
{
if
(
res
.
errMsg
!=
"checkJsApi:ok"
)
{
alert
(
"JS-SDK接口检测失败:"
+
JSON
.
stringify
(
res
));
return
false
;
}
}
})
wxRequest
(
'/workWx/auth/base/getAgentJsSdkSignature'
,
qs
.
stringify
(
data
),
header
).
then
(
res
=>
{
if
(
res
.
result
==
'success'
)
{
let
agentConfig
=
res
.
data
wx
.
agentConfig
({
corpid
:
agentConfig
.
agentJsApiSignature
.
appId
,
// 必填,企业微信的corpid,必须与当前登录的企业一致
agentid
:
agentConfig
.
agentId
,
// 必填,企业微信的应用id
timestamp
:
agentConfig
.
agentJsApiSignature
.
timestamp
,
// 必填,生成签名的时间戳
nonceStr
:
agentConfig
.
agentJsApiSignature
.
nonceStr
,
// 必填,生成签名的随机串
signature
:
agentConfig
.
agentJsApiSignature
.
signature
,
// 必填,签名,agentConfig所以为应用签名
jsApiList
:
[
'getCurExternalContact'
],
//必填
success
:
function
(
res
)
{
// alert('agentConfig:ok')
// router.push(to)
getUnionid
(
to
)
// 回调
//1、发起申请申请时后,审批状态发生变化时
//2、发起申请申请时后,在“审批中”状态,有任意审批人进行审批操作时
// alert('wx.agentConfig 回调'+res.errMsg);
},
fail
:
function
(
res
)
{
if
(
res
.
errMsg
.
indexOf
(
'is not a function'
)
>
-
1
)
{
alert
(
'<i class="weui-icon-warn">版本过低请升级</i>'
)
}
}
})
}
})
})
}
else
{
this
.
$message
({
type
:
'error'
,
message
:
res
.
errorMsg
})
}
}).
catch
(
err
=>
{
console
.
log
(
err
,
'err'
)
})
}
function
getUnionid
(
to
)
{
wx
.
invoke
(
'getCurExternalContact'
,
{},
function
(
res
)
{
if
(
res
.
err_msg
==
"getCurExternalContact:ok"
)
{
let
header
=
{
token
:
sessionStorage
.
getItem
(
'XToken'
),
corpId
:
'wwd1cdbca7b8b2b6c4'
,
agentId
:
'1000009'
,
}
let
postData
=
{
userId
:
res
.
userId
}
wxRequest
(
'/workWx/auth/contact/getExternalContact'
,
postData
,
header
,
'get'
).
then
(
res
=>
{
if
(
res
.
result
==
'success'
)
{
sessionStorage
.
setItem
(
'unionid'
,
res
.
data
.
externalContact
.
unionId
)
router
.
push
(
to
)
}
})
}
else
{
console
.
log
(
res
,
'res'
)
}
});
}
export
{
getXToken
,
configWx
,
getUnionid
}
ybf_wx/src/utils/
requestCf
.js
→
ybf_wx/src/utils/
aRequest
.js
View file @
0af9e069
import
axios
from
'axios'
import
axios
from
'axios'
import
{
Message
,
MessageBox
}
from
'element-ui'
import
{
Message
,
MessageBox
}
from
'element-ui'
//
import Router from '../router'
import
Router
from
'../router'
// import store from '../store'
// import store from '../store'
// import { getToken } from '@/utils/auth'
// import { getToken } from '@/utils/auth'
const
testEnv
=
require
(
'../../config/dev.env'
)
// const testEnv = require('../../config/dev.env')
// Z-BasicInfo
let
INFO
=
{
corpId
:
'wwd1cdbca7b8b2b6c4'
,
agentId
:
'1000015'
,
url
:
'http://139.155.48.151:8085'
,
}
// 创建axios实例
// 创建axios实例
const
service
=
axios
.
create
({
const
service
=
axios
.
create
({
baseURL
:
testEnv
.
BASE_API
,
// api 的 base_url
baseURL
:
INFO
.
url
,
// api 的 base_url
timeout
:
50000
// 请求超时时间
timeout
:
50000
// 请求超时时间
})
})
...
@@ -16,8 +23,7 @@ service.interceptors.request.use(
...
@@ -16,8 +23,7 @@ service.interceptors.request.use(
(
config
)
=>
{
(
config
)
=>
{
if
(
sessionStorage
[
'token'
])
{
if
(
sessionStorage
[
'token'
])
{
config
.
headers
[
'token'
]
=
sessionStorage
[
'token'
]
config
.
headers
[
'token'
]
=
sessionStorage
[
'token'
]
config
.
headers
[
'corpId'
]
=
'wwd1cdbca7b8b2b6c4'
config
.
headers
[
'businessId'
]
=
sessionStorage
[
'businessId'
]
config
.
headers
[
'agentId'
]
=
'1000015'
}
else
{
}
else
{
config
.
headers
[
'businessId'
]
=
'10'
config
.
headers
[
'businessId'
]
=
'10'
}
}
...
...
ybf_wx/src/utils/
requestWx
.js
→
ybf_wx/src/utils/
aWxRequest
.js
View file @
0af9e069
import
axios
from
'axios'
import
axios
from
'axios'
export
function
wxRequest
(
url
,
data
=
{},
header
=
{},
method
=
'post'
)
{
export
function
wxRequest
(
inUrl
,
data
=
{},
header
=
{},
method
=
'post'
)
{
// let URL = `http://172.16.0.111:8081${url}`
// let URL = `http://172.16.0.111:8081${url}`
let
URL
=
`http://139.155.48.151:8081
${
url
}
`
// let URL = `http://139.155.48.151:8081${url}`
if
(
method
==
'post'
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
// Z-BasicInfo
let
INFO
=
{
corpId
:
'wwd1cdbca7b8b2b6c4'
,
agentId
:
'1000015'
,
url
:
'http://139.155.48.151:8085'
+
inUrl
,
}
if
(
method
==
'post'
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
axios
({
axios
({
url
:
URL
,
url
:
INFO
.
url
,
method
:
method
,
method
:
method
,
headers
:
header
,
headers
:
header
,
data
:
data
data
:
data
...
@@ -17,10 +25,11 @@ export function wxRequest (url, data={}, header={}, method='post') {
...
@@ -17,10 +25,11 @@ export function wxRequest (url, data={}, header={}, method='post') {
})
})
})
})
}
}
if
(
method
==
'get'
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
method
==
'get'
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
axios
({
axios
({
url
:
URL
,
url
:
INFO
.
url
,
method
:
method
,
method
:
method
,
headers
:
header
,
headers
:
header
,
params
:
data
params
:
data
...
@@ -31,5 +40,5 @@ export function wxRequest (url, data={}, header={}, method='post') {
...
@@ -31,5 +40,5 @@ export function wxRequest (url, data={}, header={}, method='post') {
})
})
})
})
}
}
}
}
\ No newline at end of file
ybf_wx/src/utils/
r
equestEa.js
→
ybf_wx/src/utils/
bR
equestEa.js
View file @
0af9e069
...
@@ -43,9 +43,9 @@ const service = axios.create({
...
@@ -43,9 +43,9 @@ const service = axios.create({
// request 拦截器
// request 拦截器
service
.
interceptors
.
request
.
use
(
service
.
interceptors
.
request
.
use
(
re
s
=>
{
re
q
=>
{
// log('--->axios: re
s.data:', res
.data)
// log('--->axios: re
q.data:', req
.data)
let
oldPostData
=
JSON
.
parse
(
JSON
.
stringify
(
re
s
.
data
))
let
oldPostData
=
JSON
.
parse
(
JSON
.
stringify
(
re
q
.
data
))
let
newPostData
=
{
let
newPostData
=
{
appUser
:
basicInfo
.
appUser
,
appUser
:
basicInfo
.
appUser
,
appCode
:
oldPostData
.
args
.
appCode
,
appCode
:
oldPostData
.
args
.
appCode
,
...
@@ -67,9 +67,9 @@ service.interceptors.request.use(
...
@@ -67,9 +67,9 @@ service.interceptors.request.use(
zlog
()
zlog
()
re
s
.
data
=
postData
re
q
.
data
=
postData
return
re
s
return
re
q
},
},
error
=>
{
error
=>
{
Promise
.
reject
(
error
)
Promise
.
reject
(
error
)
...
...
ybf_wx/src/utils/
r
equestEaPost.js
→
ybf_wx/src/utils/
bR
equestEaPost.js
View file @
0af9e069
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment