获取二维码ticket后,开发者可以用ticket换取二维码图片。该操作无须登录或授权即可调用。
换取二维码的请求接口如下(注意Ticket需UrlEncode)。
https:// mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
ticket正确的情况下,HTTP返回码是200,是一张图片,可以直接展示或者下载。
上述接口运行后,返回的HTTP头示例如下。其中,url即二维码的图片地址。
{ "url": "https:// mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQHi8DoAAAAAAAAAASxod HRwOi8vd2VpeGluLnFxLmNvbS9xL0UweTNxNi1sdlA3RklyRnNKbUFvAAIELdnUUgMEAAAAAA%3D%3D", "content_type": "image/jpg", "http_code": 200, "header_size": 162, "request_size": 181, "filetime": -1, "ssl_verify_result": 20, "redirect_count": 0, "total_time": 0.509, "namelookup_time": 0, "connect_time": 0.058, "pretransfer_time": 0.343, "size_upload": 0, "size_download": 28497, "speed_download": 55986, "speed_upload": 0, "download_content_length": 28497, "upload_content_length": 0, "starttransfer_time": 0.481, "redirect_time": 0}
下面分别是两种场景二维码的URL。
https:// mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFK8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3kweXE0T3JscWY3UTltc3ZPMklvAAIEG9jUUgMECAcAAA%3d%3dhttps:// mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQHi8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0UweTNxNi1sdlA3RklyRnNKbUFvAAIELdnUUgMEAAAAAA%3d%3d
上述URL代码的二维码图片如图8-2所示。
图8-2 临时二维码和永久二维码