| 13 | |
| 14 | @urlmatch(netloc=r'(.*\.)?api\.weixin\.qq\.com$') |
| 15 | def api_weixin_mock(url, request): |
| 16 | path = url.path.replace('/cgi-bin/', '').replace('/', '_') |
| 17 | if path.startswith('_'): |
| 18 | path = path[1:] |
| 19 | res_file = os.path.join(FIXTURE_PATH, '%s.json' % path) |
| 20 | content = { |
| 21 | 'errcode': 99999, |
| 22 | 'errmsg': 'can not find fixture %s' % res_file, |
| 23 | } |
| 24 | headers = { |
| 25 | 'Content-Type': 'application/json' |
| 26 | } |
| 27 | try: |
| 28 | with open(res_file, 'rb') as f: |
| 29 | content = json.loads(f.read().decode('utf-8')) |
| 30 | except (IOError, ValueError) as e: |
| 31 | print(e) |
| 32 | return response(200, content, headers, request=request) |