rukou.js 1.38 KB
Newer Older
hanpeng committed
1 2 3 4 5 6 7 8 9
define(['zepto','medtap'],function($,medtap){
	var rukou = {
		wechatId:medtap.getRequest('wechatId'),
		init:function(){
			rukou.getToken()
		},
		checkUser:function(){
			medtap.loading(1);
			medtap.submitAjax({
10
				url:'https://gateway.medtap.cn/wechat/user/getWechatUser',
hanpeng committed
11 12 13 14 15 16 17 18 19 20 21 22
				type:'GET',
				async: false,
				data:{
					wechatId:rukou.wechatId
				},
				success:function(res){
					medtap.loading(0);
					var info = res.content.wechatUser;
					if(info.hasOwnProperty('userId')){
						//medtap.pushWindow('index.html?wechatId=' + rukou.wechatId)
						window.location.replace('index.html?wechatId=' + rukou.wechatId)
					}else{
23
						window.location.replace('https://review-formal.iplusmed.com/wechatForLungCancer/prd/wechat_lung_login/login.html?wechatId=' + rukou.wechatId)
hanpeng committed
24 25 26 27 28 29 30 31
					}
				}
			})
		},
		getToken:function(){
			localStorage.wxLungToken = '';
			medtap.loading(1);
			medtap.submitAjax({
32
				url: 'https://gateway.medtap.cn/user/auth/token',
hanpeng committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
				type: 'POST',
				async: false,
				contentType: 'application/json',
				data: {
					wechatId: rukou.wechatId
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						var token = res.content.token;
						localStorage.setItem('wxLungToken', token);
						rukou.checkUser();
					} else {
			
					}
				},
				error: function(res) {
					console.log(res.resultDesc);
				}
			})
		}
	}
	rukou.init();
})