|
这两天在学习itchat, 已经可以看到群成员的列表信息了, 我试了下加个好友; 但是好像没啥响应; 又去招同事试了下,确实没反应;
程序响应
代码:
res=itchat.add_friend(userName='@15d76',status=2,autoUpdate=True,verifyContent='hello from terry')
print(type(res),'\n', res)
响应
<class 'itchat.returnvalues.ReturnValue'>
{'BaseResp**e': {'Ret': 1, 'ErrMsg': '', 'RawMsg': ''}}
库函数的定义
def add_friend(self, userName, status=2, verifyContent='', autoUpdate=True):
''' Add a friend or accept a friend
* for adding status should be 2
* for accepting status should be 3
'''
url = '%s/webwxverifyuser?r=%s&pass_ticket=%s' % (
self.loginInfo['url'], int(time.time()), self.loginInfo['pass_ticket'])
data = {
'BaseRequest': self.loginInfo['BaseRequest'],
'Opcode': status, # 3
'VerifyUserListSize': 1,
'VerifyUserList': [{
'Value': userName,
'VerifyUserTicket': '', }],
'VerifyContent': verifyContent,
'SceneListCount': 1,
'SceneList': [33],
'skey': self.loginInfo['skey'], }
headers = {
'ContentType': 'application/json; charset=UTF-8',
'User-Agent' : config.USER_AGENT }
r = self.s.post(url, headers=headers,
data=json.dumps(data, ensure_ascii=False).encode('utf8', 'replace'))
if autoUpdate:
self.update_friend(userName)
return ReturnValue(rawResp**e=r)
求指教
|
|