def assignUserInfo(self, data, access_token): new_data = sh.copy(data) if data else sh.storage() exists = sh.model(self.MODEL_NAME).getByAccessToken(access_token) if not exists: return new_data res = sh.requestHtmlContent(self.USER_INFO_URL, ( 'access_token', access_token, 'oauth_consumer_key', self.getAppID(), 'openid', exists.uid, 'format', 'json', )) if not res: return new_data res = sh.loadsJson(res) if res.ret != 0: return new_data if not new_data.has_key('name'): new_data['name'] = res.nickname if res.gender == '男': new_data['sex'] = '他' elif res.gender == '女': new_data['sex'] = '她' image_file = sh.requestImageFile(res.figureurl_2) if image_file: new_data['image_file'] = image_file return new_data
def assignUserInfo(self, data, access_token): new_data = sh.copy(data) if data else sh.storage() exists = sh.model(self.MODEL_NAME).getByAccessToken(access_token) if not exists: return new_data res = sh.requestHtmlContent(self.USER_INFO_URL, ( 'access_token', access_token, 'oauth_consumer_key', self.getAppID(), 'uid', exists.uid, )) if not res: return new_data res = sh.loadsJson(res) if res.get('error_code', None): return new_data if not new_data.has_key('name'): new_data['name'] = res.screen_name if res.gender == 'm': new_data['sex'] = '他' elif res.gender == 'f': new_data['sex'] = '她' else: new_data['sex'] = '保密' image_file = sh.requestImageFile(res.avatar_large) if image_file: new_data['image_file'] = image_file return new_data
def assignUserInfo(self, data, access_token): new_data = sh.copy(data) if data else sh.storage() params = { 'method': 'users.getInfo', 'access_token': access_token, 'fields': 'name,sex,mainurl', } content = sh.loadsJson(self._request(params).partition('[')[2].rpartition(']')[0]) if not new_data.has_key('name'): new_data['username'] = content.name if str(content.sex) == '1': new_data['sex'] = '他' elif str(content.sex) == '2': new_data['sex'] = '她' image_file = sh.requestImageFile(content.mainurl) if image_file: new_data['image_file'] = image_file return new_data
def assignUserInfo(self, data, access_token): new_data = sh.copy(data) if data else sh.storage() params = { 'method': 'users.getInfo', 'access_token': access_token, 'fields': 'name,sex,mainurl', } content = sh.loadsJson( self._request(params).partition('[')[2].rpartition(']')[0]) if not new_data.has_key('name'): new_data['username'] = content.name if str(content.sex) == '1': new_data['sex'] = '他' elif str(content.sex) == '2': new_data['sex'] = '她' image_file = sh.requestImageFile(content.mainurl) if image_file: new_data['image_file'] = image_file return new_data