Skip to content

Commit

Permalink
修复 WeChatDevice get_qrcode_url 错误 (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
yqkcn committed Mar 14, 2022
1 parent 93836c6 commit d728378
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ def test_datacube_get_upstream_msg_dist_month(self):
result = self.client.datacube.get_upstream_msg_dist_month("2014-12-06", "2014-12-07")
self.assertEqual(1, len(result))

def test_device_get_qrcode_url(self):
with HTTMock(wechat_api_mock):
qrcode_url = self.client.device.get_qrcode_url(123)
self.assertEqual("https://we.qq.com/d/123", qrcode_url)
qrcode_url = self.client.device.get_qrcode_url(123, {"a": "a"})
self.assertEqual("https://we.qq.com/d/123#YT1h", qrcode_url)

def test_jsapi_get_ticket_response(self):
with HTTMock(wechat_api_mock):
result = self.client.jsapi.get_ticket()
Expand Down
2 changes: 1 addition & 1 deletion wechatpy/client/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_qrcode_url(self, ticket, data=None):
url = f"https://we.qq.com/d/{ticket}"
if data:
if isinstance(data, (dict, tuple, list)):
data = urllib.urlencode(data)
data = urllib.parse.urlencode(data)
data = to_text(base64.b64encode(to_binary(data)))
url = f"{url}#{data}"
return url
Expand Down

0 comments on commit d728378

Please sign in to comment.