def getcurrencyreat(request): try: checkrequesttoken(request) tcur = request.GET.get('tcur', None) scur = request.GET.get('scur', None) if not tcur or not scur: raise InvestError(20072) response = requests.get( 'https://sapi.k780.com/?app=finance.rate&scur=%s&tcur=%s&appkey=18220&sign=9b97118c7cf61df11c736c79ce94dcf9' % (scur, tcur)).content response = json.loads(response) if isinstance(response, dict): success = response.get('success', False) if success in ['1', True]: result = response.get('result', {}) else: raise InvestError(code=2007, msg=response.get('msg', None)) else: raise InvestError(code=2007, msg=response) return JSONResponse(SuccessResponse(result)) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: catchexcption(request) return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def getMobilePhoneAddress(request): try: tokenkey = request.META.get('HTTP_TOKEN') checkrequesttoken(tokenkey) mobile = request.GET.get('mobile', None) if not mobile: raise InvestError(20072, msg='手机号码不能为空') response = requests.get( 'http://apis.juhe.cn/mobile/get?phone={}&dtype=&key=f439062c59bb86db8156446aa9737c72' .format(mobile)).content response = json.loads(response.decode()) if isinstance(response, dict): error_code = response.get('error_code') if error_code == 0: result = response.get('result', {}) else: raise InvestError(20071, msg=response.get('reason', None)) else: raise InvestError(20071, msg=response) return JSONResponse(SuccessResponse(result)) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: catchexcption(request) return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def getcurrencyreat(request): try: tokenkey = request.META.get('HTTP_TOKEN') checkrequesttoken(tokenkey) scur = request.GET.get('scur', None) # 原币种 tcur = request.GET.get('tcur', None) # 目标币种 if not tcur or not scur: raise InvestError(20072) if scur == tcur: result = [ { "currencyF": scur, "currencyT": tcur, "currencyFD": "1", "exchange": "1", "result": "1", }, { "currencyF": tcur, "currencyT": scur, "currencyFD": "1", "exchange": "1", "result": "1", }, ] else: response = requests.get( 'http://op.juhe.cn/onebox/exchange/currency?from={}&to={}&key=92ad022726cff74d15d1d3b761701fa4' .format(scur, tcur)).content response = json.loads(response.decode()) if isinstance(response, dict): error_code = response.get('error_code') if error_code == 0: result = response.get('result', {}) else: raise InvestError(20071, msg=response.get('reason', None)) else: raise InvestError(20071, msg=response) return JSONResponse(SuccessResponse(result)) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: catchexcption(request) return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def getQRCode(request): """ 获取二维码 """ try: request.user = checkrequesttoken(request.GET.get('acw_tk')) url = request.GET.get('url', None) if url: qrcode_path = APILOG_PATH['excptionlogpath'] + 'qrcode.png' makeQRCode(url, qrcode_path) fn = open(qrcode_path, 'rb') response = StreamingHttpResponse(file_iterator(fn)) response['Content-Type'] = 'application/octet-stream' response["content-disposition"] = 'attachment;filename=qrcode.png' os.remove(qrcode_path) else: raise InvestError(50010, msg='二维码生成失败') return response except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))