<noframes id="bhrfl"><address id="bhrfl"></address>

    <address id="bhrfl"></address>

    <noframes id="bhrfl"><address id="bhrfl"><th id="bhrfl"></th></address>

    <form id="bhrfl"><th id="bhrfl"><progress id="bhrfl"></progress></th></form>

    <em id="bhrfl"><span id="bhrfl"></span></em>

    全部
    常見問題
    產品動態
    精選推薦

    舊版本適配小程序授權策略更新

    管理 管理 編輯 刪除

    1. 修改后端\app\controller\api\Auth.php文件的mpAuth 方法,替換為以下內容

    public function mpAuth()
        {
            list($code, $post_cache_key) = $this->request->params([
                'code',
                'cache_key',
            ], true);
            $session_key = Cache::get('eb_api_code_' . $post_cache_key);
            if (!$code && !$session_key)
                return app('json')->fail('授權失敗,參數有誤');
            $miniProgramService = MiniProgramService::create();
            if ($code && !$session_key) {
                try {
                    $userInfoCong = $miniProgramService->getUserInfo($code);
                    $session_key = $userInfoCong['session_key'];
                    $cache_key = md5(time() . $code);
                    Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
                } catch (Exception $e) {
                    return app('json')->fail('獲取session_key失敗,請檢查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
                }
            }
    
            $data = $this->request->params([
                ['spread_spid', 0],
                ['spread_code', ''],
                ['iv', ''],
                ['encryptedData', ''],
            ]);
    
            try {
                //解密獲取用戶信息
                $userInfo = $miniProgramService->encryptor($session_key, $data['iv'], $data['encryptedData']);
            } catch (Exception $e) {
                if ($e->getCode() == '-41003') return app('json')->fail('獲取會話密匙失敗');
                throw $e;
            }
            if (!$userInfo) return app('json')->fail('openid獲取失敗');
            if (!isset($userInfo['openId'])) $userInfo['openId'] = $userInfoCong['openid'] ?? '';
            $userInfo['unionId'] = $userInfoCong['unionid'] ?? $userInfo['unionId'] ?? '';
            if (!$userInfo['openId']) return app('json')->fail('openid獲取失敗');
    
            /** @var WechatUserRepository $make */
            $make = app()->make(WechatUserRepository::class);
            $user = $make->syncRoutineUser($userInfo['openId'], $userInfo);
            if (!$user)
                return app('json')->fail('授權失敗');
            /** @var UserRepository $make */
            $userRepository = app()->make(UserRepository::class);
            $user[1] = $userRepository->mainUser($user[1]);
            $code = intval($data['spread_code']['id'] ?? $data['spread_code']);
            //獲取是否有掃碼進小程序
            if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) {
                $data['spread_spid'] = $info['third_id'];
            }
            $userRepository->bindSpread($user[1], intval($data['spread_spid']));
            $tokenInfo = $userRepository->createToken($user[1]);
            $userRepository->loginAfter($user[1]);
    
            return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
        }

    2. 重啟 swoole 服務

    3. 修改uniappcomponents/Authorize.vue 文件,替換為以下內容

    	const app = getApp();
    	import Cache from '../utils/cache';
    	import {
    		getLogo
    	} from '../api/public';
    	import {
    		LOGO_URL
    	} from '../config/cache';
    	import {
    		mapGetters
    	} from 'vuex';
    	import Routine from '../libs/routine';
    
    	export default {
    		name: 'Authorize',
    		props: {
    			isAuto: {
    				type: Boolean,
    				default: true
    			},
    			isGoIndex: {
    				type: Boolean,
    				default: true
    			},
    			isShowAuth: {
    				type: Boolean,
    				default: false
    			}
    		},
    		data() {
    			return {
    				logoUrl: app.globalData.routine_logo,
    				canUseGetUserProfile: false,
    				code: null,
    			}
    		},
    		computed: mapGetters(['isLogin', 'userInfo']),
    		watch: {
    			isLogin(n) {
    				n === true && this.$emit('onLoadFun', this.userInfo);
    			},
    			isShowAuth(n) {
    				if (n) {
    					uni.showLoading({
    						title: '正在登錄中'
    					});
    					Routine.getCode().then(code => {
    						uni.hideLoading();
    						this.code = code;
    					}).catch(e => {
    						uni.hideLoading();
    						uni.showToast({
    							title: '登錄失敗',
    							duration: 2000
    						});
    					})
    				} else {
    					this.code = null;
    				}
    			}
    		},
    		created() {
    			if (wx.getUserProfile) {
    				this.canUseGetUserProfile = true
    			}
    			this.getLogoUrl();
    			this.setAuthStatus();
    			uni.$on('update', (data) => {
    				this.logoUrl = data.login_logo
    			})
    		},
    		mounted: function() {
    			this.$nextTick(() => {
    				this.logoUrl = app.globalData.login_logo
    			});
    		},
    		methods: {
    			setAuthStatus() {
    				Routine.authorize().then(res => {
    					if (res.islogin === false)
    						this.$emit('onLoadFun', this.userInfo);
    				}).catch(res => {
    					if (this.isAuto)
    						this.$emit('authColse', true);
    				})
    			},
    			getUserInfo(code) {
    				Routine.getUserInfo().then(res => {
    					let userInfo = res.userInfo
    					userInfo.code = code;
    					userInfo.spread_spid = this.$Cache.get("spread") || app.globalData.spid; //獲取推廣人ID
    					userInfo.spread_code = app.globalData.code; //獲取推廣人分享二維碼ID
    					Routine.authUserInfo(userInfo).then(res => {
    						uni.hideLoading();
    						this.$emit('authColse', false);
    						this.$emit('onLoadFun', this.userInfo);
    					}).catch(res => {
    						uni.hideLoading();
    						uni.showToast({
    							title: res.msg,
    							icon: 'none',
    							duration: 2000
    						});
    					})
    				}).catch(res => {
    					uni.hideLoading();
    				})
    			},
    			getUserProfile() {
    				let self = this;
    
    				Routine.getUserProfile()
    					.then(res => {
    						let userInfo = res.userInfo;
    						userInfo.code = this.code;
    						userInfo.spread_spid = app.globalData.spid; //獲取推廣人ID
    						userInfo.spread_code = app.globalData.code; //獲取推廣人分享二維碼ID
    						Routine.authUserInfo(userInfo)
    							.then(res => {
    								if (res.data.key !== undefined && res.data.key) {
    									uni.hideLoading();
    									self.authKey = res.data.key;
    									self.isPhoneBox = true;
    								} else {
    									uni.hideLoading();
    									let time = res.data.expires_time - self.$Cache.time();
    									self.$store.commit('LOGIN', {
    										token: res.data.token,
    										time: time
    									});
    								}
    							})
    							.catch(res => {
    								uni.hideLoading();
    								uni.showToast({
    									title: res.msg,
    									icon: 'none',
    									duration: 2000
    								});
    							});
    					})
    					.catch(res => {
    						uni.hideLoading();
    					});
    
    			},
    
    			setUserInfo() {
    				uni.showLoading({
    					title: '正在登錄中'
    				});
    				this.getUserInfo(this.code);
    				this.$emit('authColse', false);
    			},
    			getLogoUrl() {
    				this.logoUrl = app.globalData.routine_logo
    				// let that = this;
    				// if (Cache.has(LOGO_URL)) {
    				// 	this.logoUrl = Cache.get(LOGO_URL);
    				// 	return;
    				// }
    				// getLogo().then(res=>{
    				// 	that.logoUrl = res.data.logo_url
    				// 	Cache.set(LOGO_URL,that.logoUrl);
    				// })
    			},
    			close() {
    				let pages = getCurrentPages(),
    					currPage = pages[pages.length - 1];
    				if (this.isGoIndex) {
    					uni.switchTab({
    						url: '/pages/index/index'
    					});
    				} else {
    					this.$emit('authColse', false);
    				}
    				// if (currPage && currPage.isShowAuth != undefined){
    				// 	currPage.isShowAuth = true;
    				// }
    			},
    		}
    	}
    
    
    
    	.Popup {
    		width: 500rpx;
    		background-color: #fff;
    		position: fixed;
    		top: 50%;
    		left: 50%;
    		margin-left: -250rpx;
    		transform: translateY(-50%);
    		z-index: 1000;
    	}
    
    	.Popup {
    		.logo-auth {
    			z-index: -1;
    			position: absolute;
    			left: 50%;
    			top: 0%;
    			transform: translate(-50%, -50%);
    			width: 150rpx;
    			height: 150rpx;
    			display: flex;
    			align-items: center;
    			justify-content: center;
    			border: 8rpx solid #fff;
    			border-radius: 50%;
    			background: #fff;
    		}
    
    		image {
    			height: 42rpx;
    			margin-top: -54rpx;
    		}
    	}
    
    	.Popup .title {
    		font-size: 28rpx;
    		color: #000;
    		text-align: center;
    		margin-top: 30rpx
    	}
    
    	.Popup .tip {
    		font-size: 22rpx;
    		color: #555;
    		padding: 0 24rpx;
    		margin-top: 25rpx;
    	}
    
    	.Popup .bottom .item {
    		width: 50%;
    		height: 80rpx;
    		background-color: #eeeeee;
    		text-align: center;
    		line-height: 80rpx;
    		font-size: 24rpx;
    		color: #666;
    		margin-top: 54rpx;
    	}
    
    	.Popup .bottom .item.on {
    		width: 100%
    	}
    
    	.flex {
    		display: flex;
    	}
    
    	.Popup .bottom .item.grant {
    		font-size: 28rpx;
    		color: #fff;
    		font-weight: bold;
    		background-color: #e93323;
    		border-radius: 0;
    		padding: 0;
    	}
    
    	.mask {
    		position: fixed;
    		top: 0;
    		right: 0;
    		left: 0;
    		bottom: 0;
    		background-color: rgba(0, 0, 0, 0.65);
    		z-index: 999;
    	}
    

    4. 修改uniapplib/routine.js 文件, 在文件121行增加一下內容

    	getUserProfile(code) {
    		return new Promise((resolve, reject) => {
    			uni.getUserProfile({
    				lang: 'zh_CN',
    				desc: '用于完善會員資料', // 聲明獲取用戶個人信息后的用途,后續會展示在彈窗中,請謹慎填寫
    				success(user) {
    					if (code) user.code = code;
    					resolve({
    						userInfo: user,
    						islogin: false
    					});
    				},
    				fail(res) {
    					reject(res);
    				}
    			})
    		})
    	}

    5. 適配完成, 重新打包提交小程序代碼

    以上就是適配小程序最新授權策略的方法

    請登錄后查看

    CRMEB-慕白寒窗雪 最后編輯于2023-03-28 12:03:06

    快捷回復
    回復
    回復
    回復({{post_count}}) {{!is_user ? '我的回復' :'全部回復'}}
    排序 默認正序 回復倒序 點贊倒序

    {{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

    作者 管理員 企業

    {{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
    {{item.is_suggest == 1? '取消推薦': '推薦'}}
    沙發 板凳 地板 {{item.floor}}#
    {{item.user_info.title || '暫無簡介'}}
    附件

    {{itemf.name}}

    {{item.created_at}}  {{item.ip_address}}
    打賞
    已打賞¥{{item.reward_price}}
    {{item.like_count}}
    {{item.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復

    {{itemc.user_info.nickname}}

    {{itemc.user_name}}

    回復 {{itemc.comment_user_info.nickname}}

    附件

    {{itemf.name}}

    {{itemc.created_at}}
    打賞
    已打賞¥{{itemc.reward_price}}
    {{itemc.like_count}}
    {{itemc.showReply ? '取消回復' : '回復'}}
    刪除
    回復
    回復
    查看更多
    打賞
    已打賞¥{{reward_price}}
    3851
    {{like_count}}
    {{collect_count}}
    添加回復 ({{post_count}})

    相關推薦

    快速安全登錄

    使用微信掃碼登錄
    {{item.label}} 加精
    {{item.label}} {{item.label}} 板塊推薦 常見問題 產品動態 精選推薦 首頁頭條 首頁動態 首頁推薦
    取 消 確 定
    回復
    回復
    問題:
    問題自動獲取的帖子內容,不準確時需要手動修改. [獲取答案]
    答案:
    提交
    bug 需求 取 消 確 定
    打賞金額
    當前余額:¥{{rewardUserInfo.reward_price}}
    {{item.price}}元
    請輸入 0.1-{{reward_max_price}} 范圍內的數值
    打賞成功
    ¥{{price}}
    完成 確認打賞

    微信登錄/注冊

    切換手機號登錄

    {{ bind_phone ? '綁定手機' : '手機登錄'}}

    {{codeText}}
    切換微信登錄/注冊
    暫不綁定
    亚洲欧美字幕
    CRMEB客服

    CRMEB咨詢熱線 咨詢熱線

    400-8888-794

    微信掃碼咨詢

    CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
    返回頂部 返回頂部
    CRMEB客服