| 708 | } |
| 709 | |
| 710 | handler(res) { |
| 711 | let data = res?.data || res?.body || res; |
| 712 | if (!data) { |
| 713 | return; |
| 714 | } |
| 715 | if (typeof data === 'string') { |
| 716 | data = data.replace(/[\n\r| ]/g, ''); |
| 717 | if (data.includes("try{jsonpCB")) { |
| 718 | data = data.replace(/try{jsonpCB.*\({/, '{') |
| 719 | .replace(/}\)([;])?}catch\(e\){}/, '}') |
| 720 | } else if (data.includes('jsonpCB')) { |
| 721 | let st = data.replace(/[\n\r]/g, '').replace(/jsonpCB.*\({/, |
| 722 | '{'); |
| 723 | data = st.substring(0, st.length - 1) |
| 724 | } else if (data.match(/try{.*\({/)) { |
| 725 | data = data.replace(/try{.*\({/, '{') |
| 726 | .replace(/}\)([;])?}catch\(e\){}/, '}') |
| 727 | } else { |
| 728 | testMode ? console.log('例外', data) : '' |
| 729 | data = /.*?({.*}).*/g.exec(data)[1] |
| 730 | } |
| 731 | testMode ? console.log(data) : '' |
| 732 | testMode ? console.log('----------------分割线--------------------') |
| 733 | : '' |
| 734 | return JSON.parse(data) |
| 735 | } |
| 736 | testMode ? console.log(JSON.stringify(data)) : '' |
| 737 | testMode ? console.log('----------------分割线---------------------') : '' |
| 738 | return data; |
| 739 | } |
| 740 | |
| 741 | randomNum(length) { |
| 742 | length = length || 32; |