|
@@ -4,6 +4,8 @@ import { onLoad } from '@dcloudio/uni-app';
|
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
|
import globalConfig from '@/config/global';
|
|
import globalConfig from '@/config/global';
|
|
|
import * as ww from '@wecom/jssdk';
|
|
import * as ww from '@wecom/jssdk';
|
|
|
|
|
+import { getQyapiToken, getQyapiToken2, getQyapiUserInfo, getQyapiExternalcontact, getQyapiGroupchat} from '@/api/reportService/index';
|
|
|
|
|
+import md5 from 'js-md5';
|
|
|
|
|
|
|
|
const codeParams = ref('');
|
|
const codeParams = ref('');
|
|
|
const atoken = ref(localStorage.getItem('CommunityFillingAccessToken') || '');
|
|
const atoken = ref(localStorage.getItem('CommunityFillingAccessToken') || '');
|
|
@@ -12,74 +14,150 @@ onLoad(async (option) => {
|
|
|
const { code } = option;
|
|
const { code } = option;
|
|
|
codeParams.value = code;
|
|
codeParams.value = code;
|
|
|
}
|
|
}
|
|
|
- if (!atoken.value) {
|
|
|
|
|
|
|
+ if (!atoken.value || !localStorage.getItem('CommunityFillingAccessToken')) {
|
|
|
await getToken();
|
|
await getToken();
|
|
|
|
|
+ await getAccessToken();
|
|
|
}
|
|
}
|
|
|
await getExternalUserid();
|
|
await getExternalUserid();
|
|
|
await getGroupChatId();
|
|
await getGroupChatId();
|
|
|
})
|
|
})
|
|
|
// 获取token
|
|
// 获取token
|
|
|
const getToken = async () => {
|
|
const getToken = async () => {
|
|
|
- const res = await axios.get(`https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${globalConfig.corpid}&corpsecret=${globalConfig.secret}`)
|
|
|
|
|
- const resData = res.data || {};
|
|
|
|
|
- if (resData.errcode === 0) {
|
|
|
|
|
- const access_token = resData.access_token;
|
|
|
|
|
- localStorage.setItem('CommunityFillingAccessToken', access_token);
|
|
|
|
|
- atoken.value = access_token
|
|
|
|
|
|
|
+ const configObj = {
|
|
|
|
|
+ appid:globalConfig.appId,
|
|
|
|
|
+ secret:globalConfig.fdSecret
|
|
|
|
|
+ }
|
|
|
|
|
+ const reqMd5 = md5(`${configObj}`)
|
|
|
|
|
+ const res = await getQyapiToken({
|
|
|
|
|
+ "nonce": "123456", //uuid,不包含"-",自已生成
|
|
|
|
|
+ "sign": md5(`appid=${globalConfig.appId}&cmdid=getToken&nonce=123456&req=${reqMd5}&key=${globalConfig.fdSecret}`).toUpperCase(),
|
|
|
|
|
+ "req": reqMd5,
|
|
|
|
|
+ "encryption": 3,
|
|
|
|
|
+ "fromAppId": globalConfig.appId
|
|
|
|
|
+ });
|
|
|
|
|
+ const resData = res.result || '';
|
|
|
|
|
+ if (resData) {
|
|
|
|
|
+ atoken.value = resData
|
|
|
|
|
+ localStorage.setItem('CommunityToken', resData);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+const getAccessToken = async () => {
|
|
|
|
|
+ const configObj = {
|
|
|
|
|
+ corpid: globalConfig.appId,
|
|
|
|
|
+ corpsecret: globalConfig.fdSecret,
|
|
|
|
|
+ }
|
|
|
|
|
+ const reqMd5 = md5(`${configObj}`)
|
|
|
|
|
+ const res = await getQyapiToken2({
|
|
|
|
|
+ token: atoken.value,
|
|
|
|
|
+ nonce: "556677",
|
|
|
|
|
+ "sign": md5(`appid=${globalConfig.appId}&cmdid=9001&nonce=556677&req=${reqMd5}&key=${globalConfig.fdSecret}`).toUpperCase(),
|
|
|
|
|
+ "req": reqMd5,
|
|
|
|
|
+ "encryption": 3,
|
|
|
|
|
+ "fromAppId": globalConfig.appId
|
|
|
|
|
+ });
|
|
|
|
|
+ const resData = res.result || '{}';
|
|
|
|
|
+ if (resData) {
|
|
|
|
|
+ localStorage.setItem('CommunityFillingAccessToken', JSON.parse(resData).access_token || '');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 获取external_userid
|
|
// 获取external_userid
|
|
|
const externalUserid = ref('');
|
|
const externalUserid = ref('');
|
|
|
const getExternalUserid = async () => {
|
|
const getExternalUserid = async () => {
|
|
|
- const userRes = await axios.get(`https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=${atoken.value}&code=${codeParams.value}`)
|
|
|
|
|
- if (userRes.data && userRes.data.errcode === 0) {
|
|
|
|
|
- const exUserid = userRes.data.external_userid;
|
|
|
|
|
- externalUserid.value = exUserid;
|
|
|
|
|
- await getUnionid();
|
|
|
|
|
- } else if (userRes.data && userRes.data.errcode === 40014) {
|
|
|
|
|
- // access_token过期,重新获取
|
|
|
|
|
- await getToken();
|
|
|
|
|
- await getExternalUserid();
|
|
|
|
|
|
|
+ const configObj = {
|
|
|
|
|
+ access_token: localStorage.getItem('CommunityFillingAccessToken'),
|
|
|
|
|
+ code: codeParams.value
|
|
|
|
|
+ }
|
|
|
|
|
+ const reqMd5 = md5(`${configObj}`)
|
|
|
|
|
+ const res = await getQyapiUserInfo({
|
|
|
|
|
+ "token": atoken.value,
|
|
|
|
|
+ "nonce": "222333",
|
|
|
|
|
+ "sign": md5(`appid=${globalConfig.appId}&cmdid=9002&nonce=222333&req=${reqMd5}&key=${globalConfig.fdSecret}`).toUpperCase(),
|
|
|
|
|
+ "req": reqMd5,
|
|
|
|
|
+ "encryption": 3,
|
|
|
|
|
+ "fromAppId": globalConfig.appId
|
|
|
|
|
+ })
|
|
|
|
|
+ const resData = res.result || '{}';
|
|
|
|
|
+ if (resData) {
|
|
|
|
|
+ const userRes = JSON.parse(resData) || {}
|
|
|
|
|
+ if (userRes.errcode === 0) {
|
|
|
|
|
+ const exUserid = userRes.external_userid || '';
|
|
|
|
|
+ externalUserid.value = exUserid;
|
|
|
|
|
+ await getUnionid();
|
|
|
|
|
+ } else if (userRes.errcode === 40014) {
|
|
|
|
|
+ // access_token过期,重新获取
|
|
|
|
|
+ await getToken();
|
|
|
|
|
+ await getAccessToken();
|
|
|
|
|
+ await getExternalUserid();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 获取unionid
|
|
// 获取unionid
|
|
|
const unionidValue = ref('');
|
|
const unionidValue = ref('');
|
|
|
const getUnionid = async () => {
|
|
const getUnionid = async () => {
|
|
|
- const unionidRes = await axios.get(`https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=${atoken.value}&external_userid=${externalUserid.value}`)
|
|
|
|
|
- if (unionidRes.data && unionidRes.data.errcode === 0) {
|
|
|
|
|
- const unionid = unionidRes.data.external_contact && unionidRes.data.external_contact.unionid || '';
|
|
|
|
|
- unionidValue.value = unionid;
|
|
|
|
|
|
|
+ const configObj = {
|
|
|
|
|
+ access_token: localStorage.getItem('CommunityFillingAccessToken'),
|
|
|
|
|
+ external_userid: externalUserid.value
|
|
|
|
|
+ }
|
|
|
|
|
+ const reqMd5 = md5(`${configObj}`)
|
|
|
|
|
+ const res = await getQyapiExternalcontact({
|
|
|
|
|
+ "token": atoken.value,
|
|
|
|
|
+ "nonce": "4433345",
|
|
|
|
|
+ "sign": md5(`appid=${globalConfig.appId}&cmdid=9003&nonce=4433345&req=${reqMd5}&key=${globalConfig.fdSecret}`).toUpperCase(),
|
|
|
|
|
+ "req": reqMd5,
|
|
|
|
|
+ "encryption": 3,
|
|
|
|
|
+ "fromAppId": globalConfig.appId
|
|
|
|
|
+ })
|
|
|
|
|
+ const resData = res.result || '{}';
|
|
|
|
|
+ if (resData) {
|
|
|
|
|
+ const unionidRes = JSON.parse(resData) || {}
|
|
|
|
|
+ if (unionidRes.errcode === 0) {
|
|
|
|
|
+ const unionid = unionidRes.external_contact && unionidRes.external_contact.unionid || '';
|
|
|
|
|
+ unionidValue.value = unionid;
|
|
|
|
|
+ } else if (unionidRes.errcode === 40014) {
|
|
|
|
|
+ // access_token过期,重新获取
|
|
|
|
|
+ await getToken();
|
|
|
|
|
+ await getAccessToken();
|
|
|
|
|
+ await getExternalUserid();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 获取客户群的群ID
|
|
// 获取客户群的群ID
|
|
|
-const isQuestionEntry = ref(true); // 是否显示问题上报入口
|
|
|
|
|
|
|
+const isQuestionEntry = ref(false); // 是否显示问题上报入口
|
|
|
const ownerId = ref(''); // 群主id
|
|
const ownerId = ref(''); // 群主id
|
|
|
const getGroupChatId = async () => {
|
|
const getGroupChatId = async () => {
|
|
|
- ww.register({
|
|
|
|
|
|
|
+ ww.register({ // 调用客户端api,注册应用信息
|
|
|
corpId: globalConfig.corpid, // 必填,从企业微信后台获取
|
|
corpId: globalConfig.corpid, // 必填,从企业微信后台获取
|
|
|
agentId: globalConfig.agentId, // 必填,自建应用或授权应用的AgentID
|
|
agentId: globalConfig.agentId, // 必填,自建应用或授权应用的AgentID
|
|
|
jsApiList: ['getCurExternalChat'], // 声明需调用的API
|
|
jsApiList: ['getCurExternalChat'], // 声明需调用的API
|
|
|
});
|
|
});
|
|
|
- ww.getCurExternalChat({
|
|
|
|
|
- success(res) {
|
|
|
|
|
- axios.post(`https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token=${atoken.value}`, {
|
|
|
|
|
- "chat_id": res.chatId,
|
|
|
|
|
- "need_name": 1
|
|
|
|
|
- }).then((response: any) => {
|
|
|
|
|
- if (response.data && response.data.errcode === 0) {
|
|
|
|
|
- ownerId.value = response.data.group_chat.owner;
|
|
|
|
|
- const marr = response.data.group_chat.member_list || []
|
|
|
|
|
- const unionidArr = marr.filter((item: any) => !!(item.unionid)).map((el: any) => el.unionid)
|
|
|
|
|
- if (unionidArr.includes(unionidValue.value)) {
|
|
|
|
|
- // 证明此人在群内,能上报问题
|
|
|
|
|
- isQuestionEntry.value = true;
|
|
|
|
|
- } else {
|
|
|
|
|
- isQuestionEntry.value = false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ww.getCurExternalChat({ // 调用客户端api,获取当前客户群的群ID
|
|
|
|
|
+ async success(obj) {
|
|
|
|
|
+ const configObj = {
|
|
|
|
|
+ access_token: localStorage.getItem('CommunityFillingAccessToken'),
|
|
|
|
|
+ chat_id: obj.chatId,
|
|
|
|
|
+ need_name: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ const reqMd5 = md5(`${configObj}`)
|
|
|
|
|
+ const res = await getQyapiGroupchat({
|
|
|
|
|
+ "token": atoken.value,
|
|
|
|
|
+ "nonce": "4455366",
|
|
|
|
|
+ "sign": md5(`appid=${globalConfig.appId}&cmdid=9004&nonce=4455366&req=${reqMd5}&key=${globalConfig.fdSecret}`).toUpperCase(),
|
|
|
|
|
+ "req": reqMd5,
|
|
|
|
|
+ "encryption": 3,
|
|
|
|
|
+ "fromAppId": globalConfig.appId
|
|
|
|
|
+ })
|
|
|
|
|
+ const response = res.result || '{}';
|
|
|
|
|
+ if (response.errcode === 0) {
|
|
|
|
|
+ ownerId.value = response.group_chat && response.group_chat.owner || '';
|
|
|
|
|
+ const marr = response.group_chat && response.group_chat.member_list || []
|
|
|
|
|
+ const unionidArr = marr.filter((item: any) => !!(item.unionid)).map((el: any) => el.unionid)
|
|
|
|
|
+ if (unionidArr.includes(unionidValue.value)) {
|
|
|
|
|
+ // 证明此人在群内,能上报问题
|
|
|
|
|
+ isQuestionEntry.value = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ isQuestionEntry.value = false;
|
|
|
}
|
|
}
|
|
|
- }).catch((error: any) => {
|
|
|
|
|
- console.error('请求失败:', error);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
fail(err) {
|
|
fail(err) {
|
|
|
console.error('获取失败:', err.errMsg);
|
|
console.error('获取失败:', err.errMsg);
|