login.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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": "#FF5030",
  164. "highlightColor": "#FF5030",
  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": "#FF5030", // 协议文字颜色 默认值: #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.setStorageSync('userData',JSON.stringify(res.user));
  340. uni.$emit('refreshUserInfo',{ "isFirst":res.isFirst });
  341. uni.$emit('showHealthButler');
  342. uni.closeAuthView();
  343. if(res.isFirst){ //未完成新手任务
  344. uni.navigateTo({ url: '/pages/user/integral/points' });
  345. }
  346. else {
  347. goPage()
  348. }
  349. }
  350. else{
  351. unionid=res.unionid;
  352. console.log("qxj isMobileLoginFst",isMobileLoginFst);
  353. if(isMobileLoginFst){ //若先点击手机号登录且没有绑定微信
  354. bindWechatAct(userPhone,unionid);
  355. }else{
  356. if(res.isNew){ //是否绑定手机号
  357. bindMobile();
  358. }
  359. }
  360. }
  361. }
  362. else{
  363. uni.hideLoading();
  364. uni.showToast({title: res.msg,icon: 'none'});
  365. }
  366. },
  367. rej => {}
  368. );
  369. }
  370. export function bindMobile(type){
  371. // #ifdef APP-PLUS
  372. //uni.showLoading({title:""});
  373. const uniLogin = () => {
  374. uni.login({
  375. provider: 'univerify',
  376. univerifyStyle: { // 自定义登录框样式
  377. fullScreen: false,
  378. authButton: {
  379. "title": "绑定手机号",
  380. "normalColor": "#FF5030",
  381. "highlightColor": "#FF5030",
  382. },
  383. privacyTerms: {
  384. "defaultCheckBoxState":true, // 条款勾选框初始状态 默认值: true
  385. "isCenterHint":false, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  386. "uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  387. "checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  388. "checkBoxSize":18, // 可选 条款勾选框大小
  389. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  390. "termsColor": "#FF5030", // 协议文字颜色 默认值: #5496E3
  391. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  392. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  393. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  394. ]
  395. },
  396. },
  397. success(res){
  398. if(type==1) {
  399. loginByUniverify(res.authResult,3);
  400. } else {
  401. loginByUniverify(res.authResult,1);
  402. }
  403. },
  404. fail(res){
  405. console.log("qxj bindMobile fail",res);
  406. uni.hideLoading();
  407. uni.closeAuthView();
  408. //if (res.code != 30002 || res.code != 30003 || res.code != 30008) {
  409. //handleUniverifyError(res.code);
  410. //}
  411. if(res.errCode==30005){ //预登录失败
  412. //uni.showToast({title: "一键登录失败请检查网络和SIM卡是否可用",icon: 'none',position:'bottom'});
  413. if(!url){
  414. pages = getCurrentPages();
  415. url = pages[ pages.length - 1];
  416. }
  417. if(url&&url.route!="pages/auth/login"){
  418. uni.navigateTo({url: "/pages/auth/login?isBindMoble=1&unionid="+unionid});
  419. }
  420. }
  421. }
  422. });
  423. };
  424. uniLogin();
  425. console.log("----qxj 一键登录调用3-----");
  426. // #endif
  427. // #ifdef H5
  428. if(url&&url.route=="pages/auth/login"){
  429. return;
  430. }
  431. uni.navigateTo({
  432. url: "/pages/auth/login"
  433. });
  434. // #endif
  435. };
  436. export function loginByUniverify(authResult,type){
  437. uniCloud.callFunction({
  438. name: 'loginByMobile', // 你的云函数名称
  439. data: {
  440. access_token: authResult.access_token, // 客户端一键登录接口返回的access_token
  441. openid:authResult.openid // 客户端一键登录接口返回的openid
  442. }
  443. }).then(res => {
  444. if(res.result.errCode==0){
  445. userPhone=res.result.phoneNumber;
  446. if(type==0){ //手机号一键登录
  447. loginActionAct();
  448. }else{ //微信登录绑定手机号
  449. setPhoneAct(userPhone,unionid);
  450. }
  451. }else{
  452. uni.showToast({title:res.result.message,icon: 'none' });
  453. }
  454. }).catch(err=>{
  455. // 处理错误
  456. console.error('调用云函数失败:',err);
  457. // 详细记录错误信息
  458. console.error('错误信息:', err.errMsg);
  459. })
  460. }
  461. export function loginActionAct(){
  462. if (loginType==3 && userPhone==null) {
  463. uni.showToast({title: "请授权手机号登录",icon: 'none'});
  464. return
  465. }
  466. var data = {
  467. phone:userPhone,
  468. jpushId:registrationID,
  469. loginType:loginType,
  470. loginDevice:getLoginDevice(),
  471. source:plus.runtime.channel || source
  472. };
  473. var that=this;
  474. uni.showLoading({
  475. title:"处理中..."
  476. });
  477. login(data).then(res => {
  478. console.log("qxj login",res);
  479. uni.hideLoading();
  480. if (res.code == 200 && res.users && Object.prototype.toString.call(res.users) == '[object Array]') {
  481. uni.setStorageSync('requestParam',data)
  482. uni.setStorageSync('wechatList',res.users)
  483. uni.closeAuthView();
  484. goPage();
  485. return
  486. }
  487. if(res.code==200){
  488. if(res.isNew){
  489. userPhone=res.phone;
  490. quickWechatLogin(true);
  491. return;
  492. }
  493. uni.setStorageSync('AppToken',res.token);
  494. if(res.liveToken){
  495. uni.setStorageSync('liveToken', res.liveToken);
  496. }
  497. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  498. uni.setStorageSync('userData',JSON.stringify(res.user));
  499. uni.$emit('showHealthButler');
  500. uni.closeAuthView();
  501. if(res.isFirst){
  502. // #ifdef APP-PLUS
  503. if(plus.runtime.channel=="baidu"){ //获取百度渠道标识
  504. let bdCmdType=uni.getStorageSync("bdCmdType");
  505. if(bdCmdType!=null && parseInt(bdCmdType)<1){
  506. registerIdCode("register",1,0,res.user.userId); //注册
  507. }
  508. }
  509. // #endif
  510. uni.$emit('refreshIM');
  511. uni.navigateTo({ url: '/pages/user/integral/points' });
  512. } else {
  513. goPage();
  514. }
  515. }
  516. else{
  517. uni.showToast({title: res.msg,icon: 'none'});
  518. }
  519. }
  520. ).catch(err=>{
  521. console.log('登录失败啦',err);
  522. });
  523. }
  524. export function setPhoneAct(phone,unionId){
  525. let params={
  526. "phone":phone,
  527. "unionId":unionId,
  528. "jpushId":registrationID,
  529. "source":plus.runtime.channel || source
  530. };
  531. if(!isIOS){
  532. setPhone(params).then(res => {
  533. uni.hideLoading();
  534. if(res.code==200){
  535. uni.setStorageSync('AppToken',res.token);
  536. if(res.liveToken){
  537. uni.setStorageSync('liveToken', res.liveToken);
  538. }
  539. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  540. uni.setStorageSync('userData',JSON.stringify(res.user));
  541. uni.$emit('showHealthButler');
  542. uni.closeAuthView();
  543. goPage();
  544. }
  545. else{
  546. uni.showToast({title: res.msg,icon: 'none',duration:2000});
  547. }
  548. },
  549. rej => {}
  550. );
  551. }
  552. else{
  553. params.simExist=1;
  554. params.appleKey=appleKey;
  555. setIPhoneNumber(params).then(res => {
  556. uni.hideLoading();
  557. if(res.code==200){
  558. uni.setStorageSync('AppToken',res.token);
  559. if(res.liveToken){
  560. uni.setStorageSync('liveToken', res.liveToken);
  561. }
  562. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  563. uni.setStorageSync('userData',JSON.stringify(res.user));
  564. uni.$emit('showHealthButler');
  565. uni.closeAuthView();
  566. goPage();
  567. }
  568. else{
  569. uni.showToast({title: res.msg,icon: 'none',duration:2000});
  570. }
  571. },
  572. rej => {}
  573. );
  574. }
  575. }
  576. export function bindWechatAct(phone,code){
  577. let params={"phone":phone,"code":code,"jpushId":registrationID,"source":plus.runtime.channel || source};
  578. bindWechat(params).then(res => {
  579. uni.hideLoading();
  580. console.log("qxj bindWeChat res:"+JSON.stringify(res));
  581. if(res.code==200){
  582. uni.setStorageSync('AppToken',res.token);
  583. if(res.liveToken){
  584. uni.setStorageSync('liveToken', res.liveToken);
  585. }
  586. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  587. uni.setStorageSync('userData',JSON.stringify(res.user));
  588. uni.$emit('showHealthButler');
  589. uni.closeAuthView();
  590. goPage();
  591. // #ifdef APP-PLUS
  592. const jyJPush = uni.requireNativePlugin('JY-JPush');
  593. // jyJPush.setJYJPushAlias({userAlias: registrationID}, result=> {
  594. // console.log("qxj userAlias "+JSON.stringify(result));
  595. // });
  596. // #endif
  597. }
  598. else{
  599. uni.showToast({title: res.msg,icon: 'none'});
  600. setTimeout(function() {
  601. uni.closeAuthView();
  602. }, 1800);
  603. }
  604. },
  605. rej => {}
  606. );
  607. }
  608. export function getRegistrationID(type) {
  609. // #ifdef APP-PLUS
  610. registrationID = uni.getStorageSync("registrationID");
  611. const needUpdate = type === 'update' || !registrationID;
  612. if (needUpdate&& (plus.runtime.isAgreePrivacy() || isIOS)) {
  613. uni.getPushClientId({success: res => {
  614. if(!registrationID || registrationID != res.cid) {
  615. registrationID = res.cid
  616. uni.setStorageSync("registrationID",res.cid);
  617. if(type == 'update'&&isLogin()) {
  618. console.log("qxj getPushClientId:",res);
  619. upPushClientId(res.cid)
  620. }
  621. }
  622. },
  623. fail:(err)=> {
  624. console.log("getRegistrationID error:",err)
  625. }
  626. });
  627. }
  628. // #endif
  629. }
  630. export function handleUniverifyError(code) {
  631. const errorMap = {
  632. '-7': '检查是否配置/已通过审核',
  633. '1000': '检查是否配置/已通过审核',
  634. '1001': '检查账号一键登录服务是否正常',
  635. '1002': '检查账号余额是否充足',
  636. '4001': '校验异常,联系官方人员',
  637. '4003': '校验异常,联系官方人员',
  638. '5000': '联系官方人员',
  639. '20202': '引导用户手动开启设备流量',
  640. '30001': '联系官方人员',
  641. '30004': '联系官方人员',
  642. '30005': '不具备一键登录的使用前提,设备不支持/未开启数据流量/其他原因',
  643. '30007': '校验异常,联系官方人员',
  644. '40004': '多出现在自定义基座的场景,请确保应用已通过审核后,且已重新打包',
  645. '40047': '校验异常,联系官方人员',
  646. '40053': '校验异常,联系官方人员',
  647. '40101': '检查一下手机卡类型是否是正常运营商手机卡,关闭飞行模式后重新尝试。',
  648. '40201': '检查一下手机卡类型是否是正常运营商手机卡,关闭飞行模式后重新尝试。',
  649. '40301': '检查一下手机卡类型是否是正常运营商手机卡,关闭飞行模式后重新尝试。'
  650. };
  651. const msg = errorMap[String(code)];
  652. if (msg) {
  653. uni.showToast({
  654. title: msg,
  655. icon: 'none',
  656. position: 'bottom',
  657. duration: 6000
  658. });
  659. }
  660. }
  661. export function quickAppleLogin() {
  662. uni.login({
  663. provider: 'apple',
  664. success: function (loginRes) {
  665. appleKey = loginRes.authResult.openid
  666. const params={
  667. loginDevice:getLoginDevice(),
  668. jpushId:registrationID,
  669. source:plus.runtime.channel || source,
  670. appleKey: appleKey
  671. };
  672. uni.showLoading({
  673. title: '登录中'
  674. })
  675. loginByApple(params).then(res=>{
  676. uni.hideLoading();
  677. if(res.code==200){
  678. if(res.user!=null){
  679. uni.hideLoading();
  680. uni.setStorageSync('AppToken',res.token);
  681. if(res.liveToken){
  682. uni.setStorageSync('liveToken', res.liveToken);
  683. }
  684. uni.setStorageSync('userInfo',JSON.stringify(res.user));
  685. uni.setStorageSync('userData',JSON.stringify(res.user));
  686. uni.$emit('refreshUserInfo',{ "isFirst":res.isFirst });
  687. uni.$emit('showHealthButler');
  688. uni.closeAuthView();
  689. if(res.isFirst){ //未完成新手任务
  690. uni.navigateTo({ url: '/pages/user/integral/points' });
  691. }
  692. else {
  693. goPage()
  694. }
  695. } else {
  696. if(res.isNew){ //是否绑定手机号
  697. bindMobile(1);
  698. }
  699. }
  700. }
  701. else{
  702. uni.hideLoading();
  703. uni.showToast({title: res.msg,icon: 'none'});
  704. }
  705. }).catch(()=>{
  706. uni.hideLoading()
  707. })
  708. },
  709. fail: function (res) {
  710. if (res.code != 30002 || res.code != 30003 || res.code != 30008) {
  711. //handleUniverifyError(res.code);
  712. }
  713. // 登录授权失败
  714. // err.code错误码参考`授权失败错误码(code)说明`
  715. }
  716. });
  717. }
  718. export function getLoginDevice(){
  719. let loginDevice = "";
  720. // #ifdef APP-PLUS
  721. if(plus.runtime.isAgreePrivacy()) {
  722. let devinfo=uni.getDeviceInfo();
  723. if(devinfo!=null){
  724. loginDevice += devinfo.deviceBrand ? devinfo.deviceBrand : "";
  725. loginDevice += devinfo.deviceModel ? " " + devinfo.deviceModel : "";
  726. loginDevice += devinfo.system ? " " + devinfo.system : "";
  727. }
  728. }
  729. // #endif
  730. return loginDevice;
  731. }
  732. export function goPage() {
  733. uni.$emit('refreshIM');
  734. pages = getCurrentPages();
  735. url = pages[ pages.length - 1];
  736. if(univerifyManager) {
  737. univerifyManager.close();
  738. uni.closeAuthView();
  739. univerifyManager = null
  740. }
  741. const loginReturnUrl = uni.getStorageSync('loginReturnUrl');
  742. if(loginReturnUrl){
  743. uni.removeStorageSync('loginReturnUrl');
  744. uni.redirectTo({
  745. url: loginReturnUrl,
  746. fail: ()=>{
  747. uni.navigateTo({
  748. url: loginReturnUrl
  749. })
  750. }
  751. });
  752. return;
  753. }
  754. const wechatList = uni.getStorageSync('wechatList')
  755. if(wechatList){
  756. return uni.navigateTo({
  757. url:'/pages/auth/wechatList'
  758. })
  759. }
  760. const openUrl = uni.getStorageSync("openUrl")
  761. if(openUrl) {
  762. uni.navigateTo({
  763. url: openUrl,
  764. success: function(res) {
  765. uni.removeStorageSync("openUrl")
  766. }
  767. });
  768. } else {
  769. uni.reLaunch({
  770. url: '/pages_im/pages/conversation/conversationList/index',
  771. //url: '../course/video/living-app',
  772. animationType: 'none',
  773. animationDuration: 2000
  774. });
  775. return;
  776. if(pages.length == 1) {
  777. uni.reLaunch({
  778. url: '/pages_im/pages/conversation/conversationList/index',
  779. //url: '../course/video/living-app',
  780. animationType: 'none',
  781. animationDuration: 2000
  782. })
  783. } else {
  784. navBack()
  785. }
  786. }
  787. updateMsgDot()
  788. setSource()
  789. }
  790. export function upPushClientId(pushId) {
  791. updatePushId({pushId:pushId})
  792. }