login.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. import { login,loginByWeChat,setPhone,setIPhoneNumber,bindWechat,updatePushId,loginByApple } from '@/api/user'
  2. import { qconfig } from '@/utils/config.js';
  3. import { navBack, registerIdCode,updateMsgDot,setSource } from '@/utils/common.js';
  4. import {isLogin,checkWechatInstalled} from '@/utils/common.js'
  5. let univerifyManager=null;
  6. let registrationID=uni.getStorageSync("registrationID");
  7. let userPhone="";
  8. let unionid="";
  9. let appleKey="";
  10. let loginType=3;//1账号密码 2:微信登录 3:手机号一键登录
  11. let isMobileLoginFst=false; //标识是否先手机号登录且没有绑定微信;(该手机号用户没有微信unionId)
  12. let pages = '';
  13. let url = ''; //当前页页面实例
  14. let source = 'app';
  15. // #ifdef APP-PLUS
  16. let isIOS = plus.os.name == 'iOS';
  17. if(isIOS){
  18. source='iOS';
  19. }
  20. // #endif
  21. // #ifndef APP-PLUS
  22. source = 'h5';
  23. // #endif
  24. export function showLoginPage(){
  25. pages = getCurrentPages();
  26. url = pages[ pages.length - 1];
  27. // #ifdef APP-PLUS
  28. if(qconfig!=undefined && qconfig.applyLogin){
  29. return;
  30. }
  31. if(!isIOS){
  32. if(!plus.runtime.isAgreePrivacy()) {
  33. if(url&&url.route=="pages/auth/login"){
  34. return;
  35. }
  36. uni.navigateTo({
  37. url: "/pages/auth/login"
  38. });
  39. return;
  40. }
  41. }
  42. uni.showLoading({title:""});
  43. getRegistrationID();
  44. let that=this;
  45. univerifyManager = uni.getUniverifyManager();
  46. const loginCallBack = (resinfo) => {
  47. // 获取一键登录弹框协议勾选状态
  48. univerifyManager.getCheckBoxState({success(res) {
  49. if(qconfig!=undefined){
  50. qconfig.applyLogin=false;
  51. }
  52. uni.hideLoading();
  53. if(!res.state){
  54. uni.showToast({title: "请同意服务条款和隐私政策",icon: 'none',position:'bottom'});
  55. return;
  56. }
  57. if(resinfo.provider=='weixin') {
  58. quickWechatLogin(false);
  59. }else if(resinfo.provider=='apple') {
  60. quickAppleLogin()
  61. }
  62. // 关闭一键登录弹框
  63. univerifyManager.close();
  64. }
  65. });
  66. }
  67. if(isIOS){
  68. uni.preLogin({
  69. provider: 'univerify',
  70. success(res){ //预登录成功
  71. // 显示一键登录选项
  72. uni.hideLoading();
  73. //console.log("qxj preLogin success res",res);
  74. univerifyLogin(this);
  75. // 订阅自定义按钮点击事件
  76. univerifyManager.onButtonsClick(loginCallBack);
  77. },
  78. fail(res){ // 预登录失败
  79. // 不显示一键登录选项(或置灰)
  80. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  81. console.log("qxj preLogin fail res",res);
  82. uni.hideLoading();
  83. if(res.errCode==30005 || res.errMsg.includes("无SIM卡")){
  84. if(url&&url.route=="pages/auth/login"){
  85. return;
  86. }
  87. setTimeout(function() {
  88. uni.navigateTo({url: "/pages/auth/login"});
  89. }, 400);
  90. }
  91. }
  92. });
  93. return;
  94. }else{
  95. //手机号一键登录时
  96. univerifyLogin(this);
  97. // 订阅自定义按钮点击事件
  98. univerifyManager.onButtonsClick(loginCallBack);
  99. // 取消订阅自定义按钮点击事件
  100. //univerifyManager.offButtonsClick(loginCallBack);
  101. if(qconfig!=undefined){
  102. qconfig.applyLogin=true;
  103. }
  104. uni.hideLoading();
  105. }
  106. // #endif
  107. // #ifdef H5
  108. if(String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger"){
  109. let url=window.location.href;
  110. //let urlPaths=url.split("/h5");
  111. let urlPaths=url.split("/pages");
  112. let pagePath="/pages"+urlPaths[1];
  113. uni.setStorageSync('beforLoginPage',pagePath);
  114. uni.navigateTo({
  115. url: "/pages/auth/h5WxLogin"
  116. });
  117. }
  118. else{
  119. if(url&&url.route=="pages/auth/login"){
  120. return;
  121. }
  122. uni.navigateTo({
  123. url: "/pages/auth/login"
  124. });
  125. }
  126. // #endif
  127. }
  128. const univerifyLogin=function(that){
  129. let buttonslist=[
  130. {
  131. "provider": "weixin",
  132. "iconPath": "/static/image/login/weixin.png" // 图标路径仅支持本地图片
  133. }
  134. ];
  135. if(isIOS) {
  136. if(checkWechatInstalled()){
  137. buttonslist=[
  138. {
  139. "provider": "weixin",
  140. "iconPath": "/static/image/login/weixin.png" // 图标路径仅支持本地图片
  141. },
  142. {
  143. "provider": "apple",
  144. "iconPath": "/static/image/login/apple.png" // 图标路径仅支持本地图片
  145. }
  146. ]
  147. }
  148. else{
  149. buttonslist=[
  150. {
  151. "provider": "apple",
  152. "iconPath": "/static/image/login/apple.png" // 图标路径仅支持本地图片
  153. }
  154. ]
  155. }
  156. }
  157. univerifyManager.login({
  158. provider: 'univerify',
  159. univerifyStyle: { // 自定义登录框样式
  160. fullScreen: !isIOS,
  161. authButton: {
  162. "title": "本机号码一键登录",
  163. "normalColor": "#FF5C03",
  164. "highlightColor": "#FF5C03",
  165. "disabledColor": "#FFA366",
  166. },
  167. otherLoginButton: {
  168. "title": "快捷登录",
  169. "visible": "false",
  170. },
  171. navBar: {
  172. backgroundColor: "#ffffff",
  173. title: ""
  174. },
  175. logo: {
  176. "path": "static/image/login/top_bg.png",
  177. "width": "0px",
  178. "height": "0px"
  179. },
  180. closeIcon: {
  181. "path": "static/images/icon_close.png",
  182. "width": "24px",
  183. "height": "24px"
  184. },
  185. // buttons: {
  186. // "iconWidth": "44px", // 图标宽度(高度等比例缩放) 默认值:45px
  187. // "list": buttonslist
  188. // },
  189. privacyTerms: {
  190. "defaultCheckBoxState":false, // 条款勾选框初始状态 默认值: true
  191. "isCenterHint":false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  192. "uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  193. "checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  194. "checkBoxSize":22, // 可选 条款勾选框大小
  195. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  196. "termsColor": "#FF5C03", // 协议文字颜色 默认值: #5496E3
  197. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  198. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  199. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  200. {
  201. "url": "https://userapp.his.cdwjyyh.com/web/userAgreement", // 点击跳转的协议详情页面
  202. "title": "用户服务协议" // 协议名称
  203. },
  204. {
  205. "url": "https://userapp.his.cdwjyyh.com/web/privacyPolicy", // 点击跳转的协议详情页面
  206. "title": "隐私保护" // 协议名称
  207. }
  208. ]
  209. },
  210. },
  211. success(res){ // 登录成功
  212. console.log("qxj univerify login:"+JSON.stringify(res.authResult)); // {openid:'登录授权唯一标识',access_token:'接口返
  213. uni.hideLoading();
  214. if(qconfig!=undefined){
  215. qconfig.applyLogin=false;
  216. }
  217. loginType=3;
  218. loginByUniverify(res.authResult,0);
  219. },
  220. fail(res){
  221. console.log("qxj fail res",res);
  222. uni.hideLoading();
  223. if(qconfig!=undefined){
  224. qconfig.applyLogin=false;
  225. }
  226. // if (res.code != 30002 || res.code != 30003 || res.code != 30008) {
  227. // handleUniverifyError(res.code);
  228. // }
  229. if(res.code==30008){ //用户点击了自定义按钮
  230. uni.getCheckBoxState({
  231. success(response){
  232. if(!response.state){
  233. uni.showToast({title: "请同意服务条款和隐私政策",icon: 'none',position:'bottom'});
  234. return;
  235. }
  236. if(res.provider=='weixin') {
  237. quickWechatLogin(false);
  238. }else if(res.provider=='apple') {
  239. quickAppleLogin()
  240. }
  241. },
  242. fail(err){
  243. // console.log(err.errCode)
  244. // console.log(err.errMsg)
  245. }
  246. });
  247. console.log("----qxj 一键登录调用2-----");
  248. }
  249. else if(res.code==30003){ //关闭验证界面
  250. univerifyManager.close();
  251. return false;
  252. }
  253. else if(res.code==30005){ //预登录失败
  254. // uni.showToast({title: "一键登录失败请检查网络和SIM卡是否可用",icon: 'none',position:'bottom'});
  255. if(url&&url.route=="pages/auth/login"){
  256. return;
  257. }
  258. setTimeout(function() {
  259. uni.navigateTo({url: "/pages/auth/login"});
  260. }, 400);
  261. }
  262. }
  263. });
  264. };
  265. export function quickWechatLogin(isMobileLogin){
  266. isMobileLoginFst=isMobileLogin;
  267. loginType=2;
  268. uni.login({
  269. provider: "weixin",
  270. onlyAuthorize:true,
  271. success: async (res) => {
  272. let that=this;
  273. uni.showLoading({
  274. title:"处理中..."
  275. });
  276. if(isMobileLogin){
  277. bindWechatAct(userPhone,res.code);
  278. }
  279. else{
  280. const params={"code":res.code,"loginDevice":getLoginDevice(),"jpushId":registrationID,"source":plus.runtime.channel || source};
  281. loginByWeChatAct(params);
  282. }
  283. },
  284. fail: (err) => {
  285. console.log('login fail:', JSON.stringify(err));
  286. // 未开通
  287. if (err.code == 1000) {
  288. uni.showModal({
  289. title: '登录失败',
  290. content: `${err.errMsg}\n,错误码:${err.code}`,
  291. confirmText: '开通指南',
  292. cancelText: '确定',
  293. success: (res) => {
  294. if (res.confirm) {
  295. setTimeout(() => {
  296. plus.runtime.openWeb('https://ask.dcloud.net.cn/article/37965')
  297. }, 500)
  298. }
  299. }
  300. });
  301. return;
  302. }
  303. // if (res.code != 30002 || res.code != 30003 || res.code != 30008) {
  304. // handleUniverifyError(res.code);
  305. // }
  306. // 一键登录预登陆失败
  307. if (err.code == 30005) {
  308. uni.showModal({
  309. showCancel: false,
  310. title: '预登录失败',
  311. content: err.errMsg
  312. });
  313. return;
  314. }
  315. // 一键登录用户关闭验证界面
  316. if (err.code != 30003) {
  317. uni.showModal({
  318. showCancel: false,
  319. title: '登录失败',
  320. content: JSON.stringify(err)
  321. });
  322. }
  323. },
  324. complete: () => {
  325. }
  326. });
  327. };
  328. export function loginByWeChatAct(params){
  329. loginByWeChat(params).then(res => {
  330. console.log("qxj loginByWeChat res",res);
  331. if(res.code==200){
  332. if(res.user!=null){
  333. uni.hideLoading();
  334. uni.setStorageSync('AppToken',res.token);
  335. if(res.liveToken){
  336. uni.setStorageSync('liveToken', res.liveToken);
  337. }
  338. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  339. uni.$emit('refreshUserInfo',{ "isFirst":res.isFirst });
  340. uni.$emit('showHealthButler');
  341. uni.closeAuthView();
  342. if(res.isFirst){ //未完成新手任务
  343. uni.navigateTo({ url: '/pages/user/integral/points' });
  344. }
  345. else {
  346. goPage()
  347. }
  348. }
  349. else{
  350. unionid=res.unionid;
  351. console.log("qxj isMobileLoginFst",isMobileLoginFst);
  352. if(isMobileLoginFst){ //若先点击手机号登录且没有绑定微信
  353. bindWechatAct(userPhone,unionid);
  354. }else{
  355. if(res.isNew){ //是否绑定手机号
  356. bindMobile();
  357. }
  358. }
  359. }
  360. }
  361. else{
  362. uni.hideLoading();
  363. uni.showToast({title: res.msg,icon: 'none'});
  364. }
  365. },
  366. rej => {}
  367. );
  368. }
  369. export function bindMobile(type){
  370. // #ifdef APP-PLUS
  371. //uni.showLoading({title:""});
  372. const uniLogin = () => {
  373. uni.login({
  374. provider: 'univerify',
  375. univerifyStyle: { // 自定义登录框样式
  376. fullScreen: false,
  377. authButton: {
  378. "title": "绑定手机号",
  379. "normalColor": "#FF5C03",
  380. "highlightColor": "#FF5C03",
  381. },
  382. privacyTerms: {
  383. "defaultCheckBoxState":true, // 条款勾选框初始状态 默认值: true
  384. "isCenterHint":false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  385. "uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  386. "checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  387. "checkBoxSize":18, // 可选 条款勾选框大小
  388. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  389. "termsColor": "#FF5C03", // 协议文字颜色 默认值: #5496E3
  390. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  391. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  392. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  393. ]
  394. },
  395. },
  396. success(res){
  397. if(type==1) {
  398. loginByUniverify(res.authResult,3);
  399. } else {
  400. loginByUniverify(res.authResult,1);
  401. }
  402. },
  403. fail(res){
  404. console.log("qxj bindMobile fail",res);
  405. uni.hideLoading();
  406. uni.closeAuthView();
  407. //if (res.code != 30002 || res.code != 30003 || res.code != 30008) {
  408. //handleUniverifyError(res.code);
  409. //}
  410. if(res.errCode==30005){ //预登录失败
  411. //uni.showToast({title: "一键登录失败请检查网络和SIM卡是否可用",icon: 'none',position:'bottom'});
  412. if(!url){
  413. pages = getCurrentPages();
  414. url = pages[ pages.length - 1];
  415. }
  416. if(url&&url.route!="pages/auth/login"){
  417. uni.navigateTo({url: "/pages/auth/login?isBindMoble=1&unionid="+unionid});
  418. }
  419. }
  420. }
  421. });
  422. };
  423. uniLogin();
  424. console.log("----qxj 一键登录调用3-----");
  425. // #endif
  426. // #ifdef H5
  427. if(url&&url.route=="pages/auth/login"){
  428. return;
  429. }
  430. uni.navigateTo({
  431. url: "/pages/auth/login"
  432. });
  433. // #endif
  434. };
  435. export function loginByUniverify(authResult,type){
  436. uniCloud.callFunction({
  437. name: 'loginByMobile', // 你的云函数名称
  438. data: {
  439. access_token: authResult.access_token, // 客户端一键登录接口返回的access_token
  440. openid:authResult.openid // 客户端一键登录接口返回的openid
  441. }
  442. }).then(res => {
  443. if(res.result.errCode==0){
  444. userPhone=res.result.phoneNumber;
  445. if(type==0){ //手机号一键登录
  446. loginActionAct();
  447. }else{ //微信登录绑定手机号
  448. setPhoneAct(userPhone,unionid);
  449. }
  450. }else{
  451. uni.showToast({title:res.result.message,icon: 'none' });
  452. }
  453. }).catch(err=>{
  454. // 处理错误
  455. console.error('调用云函数失败:',err);
  456. // 详细记录错误信息
  457. console.error('错误信息:', err.errMsg);
  458. })
  459. }
  460. export function loginActionAct(){
  461. if (loginType==3 && userPhone==null) {
  462. uni.showToast({title: "请授权手机号登录",icon: 'none'});
  463. return
  464. }
  465. var data = {
  466. phone:userPhone,
  467. jpushId:registrationID,
  468. loginType:loginType,
  469. loginDevice:getLoginDevice(),
  470. source:plus.runtime.channel || source
  471. };
  472. var that=this;
  473. uni.showLoading({
  474. title:"处理中..."
  475. });
  476. login(data).then(res => {
  477. uni.hideLoading();
  478. if (res.code == 200 && res.users && Object.prototype.toString.call(res.users) == '[object Array]') {
  479. uni.setStorageSync('requestParam',data)
  480. uni.setStorageSync('wechatList',res.users)
  481. uni.closeAuthView();
  482. goPage();
  483. return
  484. }
  485. if(res.code==200){
  486. if(res.isNew){
  487. userPhone=res.phone;
  488. quickWechatLogin(true);
  489. return;
  490. }
  491. uni.setStorageSync('AppToken',res.token);
  492. if(res.liveToken){
  493. uni.setStorageSync('liveToken', res.liveToken);
  494. }
  495. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  496. uni.$emit('showHealthButler');
  497. uni.closeAuthView();
  498. if(res.isFirst){
  499. // #ifdef APP-PLUS
  500. if(plus.runtime.channel=="baidu"){ //获取百度渠道标识
  501. let bdCmdType=uni.getStorageSync("bdCmdType");
  502. if(bdCmdType!=null && parseInt(bdCmdType)<1){
  503. registerIdCode("register",1,0,res.user.userId); //注册
  504. }
  505. }
  506. // #endif
  507. uni.$emit('refreshIM');
  508. uni.navigateTo({ url: '/pages/user/integral/points' });
  509. } else {
  510. goPage();
  511. }
  512. }
  513. else{
  514. uni.showToast({title: res.msg,icon: 'none'});
  515. }
  516. }
  517. ).catch(err=>{
  518. console.log('登录失败啦',err);
  519. });
  520. }
  521. export function setPhoneAct(phone,unionId){
  522. let params={
  523. "phone":phone,
  524. "unionId":unionId,
  525. "jpushId":registrationID,
  526. "source":plus.runtime.channel || source
  527. };
  528. if(!isIOS){
  529. setPhone(params).then(res => {
  530. uni.hideLoading();
  531. if(res.code==200){
  532. uni.setStorageSync('AppToken',res.token);
  533. if(res.liveToken){
  534. uni.setStorageSync('liveToken', res.liveToken);
  535. }
  536. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  537. uni.$emit('showHealthButler');
  538. uni.closeAuthView();
  539. goPage();
  540. }
  541. else{
  542. uni.showToast({title: res.msg,icon: 'none',duration:2000});
  543. }
  544. },
  545. rej => {}
  546. );
  547. }
  548. else{
  549. params.simExist=1;
  550. params.appleKey=appleKey;
  551. setIPhoneNumber(params).then(res => {
  552. uni.hideLoading();
  553. if(res.code==200){
  554. uni.setStorageSync('AppToken',res.token);
  555. if(res.liveToken){
  556. uni.setStorageSync('liveToken', res.liveToken);
  557. }
  558. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  559. uni.$emit('showHealthButler');
  560. uni.closeAuthView();
  561. goPage();
  562. }
  563. else{
  564. uni.showToast({title: res.msg,icon: 'none',duration:2000});
  565. }
  566. },
  567. rej => {}
  568. );
  569. }
  570. }
  571. export function bindWechatAct(phone,code){
  572. let params={"phone":phone,"code":code,"jpushId":registrationID,"source":plus.runtime.channel || source};
  573. bindWechat(params).then(res => {
  574. uni.hideLoading();
  575. console.log("qxj bindWeChat res:"+JSON.stringify(res));
  576. if(res.code==200){
  577. uni.setStorageSync('AppToken',res.token);
  578. if(res.liveToken){
  579. uni.setStorageSync('liveToken', res.liveToken);
  580. }
  581. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  582. uni.$emit('showHealthButler');
  583. uni.closeAuthView();
  584. goPage();
  585. // #ifdef APP-PLUS
  586. const jyJPush = uni.requireNativePlugin('JY-JPush');
  587. // jyJPush.setJYJPushAlias({userAlias: registrationID}, result=> {
  588. // console.log("qxj userAlias "+JSON.stringify(result));
  589. // });
  590. // #endif
  591. }
  592. else{
  593. uni.showToast({title: res.msg,icon: 'none'});
  594. setTimeout(function() {
  595. uni.closeAuthView();
  596. }, 1800);
  597. }
  598. },
  599. rej => {}
  600. );
  601. }
  602. export function getRegistrationID(type) {
  603. // #ifdef APP-PLUS
  604. registrationID = uni.getStorageSync("registrationID");
  605. const needUpdate = type === 'update' || !registrationID;
  606. if (needUpdate&& (plus.runtime.isAgreePrivacy() || isIOS)) {
  607. uni.getPushClientId({success: res => {
  608. if(!registrationID || registrationID != res.cid) {
  609. registrationID = res.cid
  610. uni.setStorageSync("registrationID",res.cid);
  611. if(type == 'update'&&isLogin()) {
  612. console.log("qxj getPushClientId:",res);
  613. upPushClientId(res.cid)
  614. }
  615. }
  616. },
  617. fail:(err)=> {
  618. console.log("getRegistrationID error:",err)
  619. }
  620. });
  621. }
  622. // #endif
  623. }
  624. export function handleUniverifyError(code) {
  625. const errorMap = {
  626. '-7': '检查是否配置/已通过审核',
  627. '1000': '检查是否配置/已通过审核',
  628. '1001': '检查账号一键登录服务是否正常',
  629. '1002': '检查账号余额是否充足',
  630. '4001': '校验异常,联系官方人员',
  631. '4003': '校验异常,联系官方人员',
  632. '5000': '联系官方人员',
  633. '20202': '引导用户手动开启设备流量',
  634. '30001': '联系官方人员',
  635. '30004': '联系官方人员',
  636. '30005': '不具备一键登录的使用前提,设备不支持/未开启数据流量/其他原因',
  637. '30007': '校验异常,联系官方人员',
  638. '40004': '多出现在自定义基座的场景,请确保应用已通过审核后,且已重新打包',
  639. '40047': '校验异常,联系官方人员',
  640. '40053': '校验异常,联系官方人员',
  641. '40101': '检查一下手机卡类型是否是正常运营商手机卡,关闭飞行模式后重新尝试。',
  642. '40201': '检查一下手机卡类型是否是正常运营商手机卡,关闭飞行模式后重新尝试。',
  643. '40301': '检查一下手机卡类型是否是正常运营商手机卡,关闭飞行模式后重新尝试。'
  644. };
  645. const msg = errorMap[String(code)];
  646. if (msg) {
  647. uni.showToast({
  648. title: msg,
  649. icon: 'none',
  650. position: 'bottom',
  651. duration: 6000
  652. });
  653. }
  654. }
  655. export function quickAppleLogin() {
  656. uni.login({
  657. provider: 'apple',
  658. success: function (loginRes) {
  659. appleKey = loginRes.authResult.openid
  660. const params={
  661. loginDevice:getLoginDevice(),
  662. jpushId:registrationID,
  663. source:plus.runtime.channel || source,
  664. appleKey: appleKey
  665. };
  666. uni.showLoading({
  667. title: '登录中'
  668. })
  669. loginByApple(params).then(res=>{
  670. uni.hideLoading();
  671. if(res.code==200){
  672. if(res.user!=null){
  673. uni.hideLoading();
  674. uni.setStorageSync('AppToken',res.token);
  675. if(res.liveToken){
  676. uni.setStorageSync('liveToken', res.liveToken);
  677. }
  678. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  679. uni.$emit('refreshUserInfo',{ "isFirst":res.isFirst });
  680. uni.$emit('showHealthButler');
  681. uni.closeAuthView();
  682. if(res.isFirst){ //未完成新手任务
  683. uni.navigateTo({ url: '/pages/user/integral/points' });
  684. }
  685. else {
  686. goPage()
  687. }
  688. } else {
  689. if(res.isNew){ //是否绑定手机号
  690. bindMobile(1);
  691. }
  692. }
  693. }
  694. else{
  695. uni.hideLoading();
  696. uni.showToast({title: res.msg,icon: 'none'});
  697. }
  698. }).catch(()=>{
  699. uni.hideLoading()
  700. })
  701. },
  702. fail: function (res) {
  703. if (res.code != 30002 || res.code != 30003 || res.code != 30008) {
  704. //handleUniverifyError(res.code);
  705. }
  706. // 登录授权失败
  707. // err.code错误码参考`授权失败错误码(code)说明`
  708. }
  709. });
  710. }
  711. export function getLoginDevice(){
  712. let loginDevice = "";
  713. // #ifdef APP-PLUS
  714. if(plus.runtime.isAgreePrivacy()) {
  715. let devinfo=uni.getDeviceInfo();
  716. if(devinfo!=null){
  717. loginDevice += devinfo.deviceBrand ? devinfo.deviceBrand : "";
  718. loginDevice += devinfo.deviceModel ? " " + devinfo.deviceModel : "";
  719. loginDevice += devinfo.system ? " " + devinfo.system : "";
  720. }
  721. }
  722. // #endif
  723. return loginDevice;
  724. }
  725. export function goPage() {
  726. uni.$emit('refreshIM');
  727. pages = getCurrentPages();
  728. url = pages[ pages.length - 1];
  729. if(univerifyManager) {
  730. univerifyManager.close();
  731. uni.closeAuthView();
  732. univerifyManager = null
  733. }
  734. const loginReturnUrl = uni.getStorageSync('loginReturnUrl');
  735. if(loginReturnUrl){
  736. uni.removeStorageSync('loginReturnUrl');
  737. uni.redirectTo({
  738. url: loginReturnUrl,
  739. fail: ()=>{
  740. uni.navigateTo({
  741. url: loginReturnUrl
  742. })
  743. }
  744. });
  745. return;
  746. }
  747. const wechatList = uni.getStorageSync('wechatList')
  748. if(wechatList){
  749. return uni.navigateTo({
  750. url:'/pages/auth/wechatList'
  751. })
  752. }
  753. const openUrl = uni.getStorageSync("openUrl")
  754. if(openUrl) {
  755. uni.navigateTo({
  756. url: openUrl,
  757. success: function(res) {
  758. uni.removeStorageSync("openUrl")
  759. }
  760. });
  761. } else {
  762. uni.reLaunch({
  763. url: '/pages_im/pages/conversation/conversationList/index',
  764. //url: '../course/video/living-app',
  765. animationType: 'none',
  766. animationDuration: 2000
  767. });
  768. return;
  769. if(pages.length == 1) {
  770. uni.reLaunch({
  771. url: '/pages_im/pages/conversation/conversationList/index',
  772. //url: '../course/video/living-app',
  773. animationType: 'none',
  774. animationDuration: 2000
  775. })
  776. } else {
  777. navBack()
  778. }
  779. }
  780. updateMsgDot()
  781. setSource()
  782. }
  783. export function upPushClientId(pushId) {
  784. updatePushId({pushId:pushId})
  785. }