def doSetUserAvatar(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params url = TyContext.RunHttp.getRequestParam('url', '').strip() data = TyContext.RunHttp.getRequestParam('data', '') mo = TyContext.Cls_MsgPack() is_url_error = len(url) > 0 and (len(url) > 125 or url.find('"') >= 0 or url.find("'") >= 0) if (len(url) == 0 and len(data) == 0) or is_url_error: mo.setResult('code', 1) mo.setResult('info', '输入参数错误') return mo if len(data) > 0: try: data = base64.b64decode(data) except: mo.setResult('code', 1) mo.setResult('info', '图像数据错误') return mo params['url'] = url params['data'] = data AccountInfo.doSetUserAvatar(params, mo) return mo
def doSetPasswd(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params # 获取玩家修改密码次数 userId = params['userId'] changePwdCount = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'changePwdCount') # TyContext.ftlog.info(cls.__name__, 'doSetPasswd->changePwdCount=', changePwdCount) if changePwdCount == None: changePwdCount = 0 if int(changePwdCount) > 0: isReturn, oldpasswd = AccountCheck.check_param_password(rpath, 'oldpasswd') if isReturn: return oldpasswd params['oldpasswd'] = oldpasswd isReturn, newpasswd = AccountCheck.check_param_password(rpath, 'newpasswd', isSet=True) if isReturn: return newpasswd params['newpasswd'] = newpasswd mo = TyContext.Cls_MsgPack() AccountInfo.doSetPasswd(params, mo) return mo
def doGetUserInfo(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params mo = TyContext.Cls_MsgPack() AccountInfo.doGetUserInfo(params, mo) return mo
def doSetUserNickName(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params isReturn, params = AccountCheck.set_user_check(rpath, params) if isReturn: return params mo = TyContext.Cls_MsgPack() AccountInfo.doSetUserNickName(params, mo) return mo
def doCheckSmsBind(cls, rpath): userId = TyContext.RunHttp.getRequestParamInt('userId', 0) if userId > 0: isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params else: isReturn, params = AccountCheck.onekeylogin_check(rpath) if isReturn: return params mo = TyContext.Cls_MsgPack() AccountSms.doCheckSmsBind(params, mo) return mo
def doReportContacts(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params mo = TyContext.Cls_MsgPack() contacts = TyContext.RunHttp.getRequestParam('contacts', '') if contacts != '': contacts = AccountVerify.decode_item(contacts) TyContext.ftlog.info('doReportContacts appId=', params['appId'], 'userId=', params['userId'], 'contacts=', contacts) mo.setResult('code', 0) mo.setResult('info', 'success') return mo
def doBindBySnsId(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params isReturn, snsId = AccountCheck.check_param_snsid(rpath) if isReturn: return snsId params['snsId'] = snsId params['snsToken'] = TyContext.RunHttp.getRequestParam('snsToken') mo = TyContext.Cls_MsgPack() AccountBind.doBindBySnsId(params, mo) return mo
def doBindMobileByVerifyCode(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params isReturn, mobile = AccountCheck.check_param_mobile(rpath) if isReturn: return mobile params['mobile'] = mobile isReturn, vcode = AccountCheck.check_param_verify_code(rpath) if isReturn: return vcode params['vcode'] = vcode mo = TyContext.Cls_MsgPack() AccountSms.doBindMobileByVerifyCode(params, mo) return mo
def doBindByEmail(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params appId = params['appId'] clientId = params['clientId'] if (appId == 6 and (clientId.find('Android_2.8_') >= 0 or clientId.find('Android_2.81_') >= 0)) or \ (appId == 7 and (clientId.find('Android_2.28_') >= 0)): mo = TyContext.Cls_MsgPack() mo.setResult('code', 1) mo.setResult('info', '暂未开通此功能') return mo isReturn, mail = AccountCheck.check_param_mail(rpath) if isReturn: return mail params['mail'] = mail mo = TyContext.Cls_MsgPack() AccountBind.doBindByEmail(params, mo) return mo
def downapp(cls, rpath): url = TyContext.RunHttp.getRequestParam('url') if url: TyContext.RunHttp.redirect(url) isReturn, params = AccountCheck.normal_check(rpath, False) if isReturn: return params clientId = params['clientId'] appId = params['appId'] pkg = TyContext.RunHttp.getRequestParam('pkg') down_app_id = TyContext.RunHttp.getRequestParam('down_app_id') url = TyContext.RunHttp.getRequestParam('url') mo = TyContext.Cls_MsgPack() mo.setCmd('downapp') if not pkg or not down_app_id or not url: mo.setResult('code', 1) mo.setResult('info', 'lack parameters') else: Cross.downapp(appId, down_app_id, clientId, params['userId'], pkg, url) mo.setResult('code', 0) mo.setResult('url', url)
def mergeSnsFriends(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params mo = TyContext.Cls_MsgPack() sns_type = TyContext.RunHttp.getRequestParam('sns_type', '') sns_friends_param = TyContext.RunHttp.getRequestParam( 'sns_friends', '') if sns_type == '' and sns_friends_param == '': mo.setResult('code', 1) mo.setResult('info', 'sns_type,sns_friends required') return mo TyContext.ftlog.info('mergeSnsFriends sns_type=', sns_type, 'appId=', params['appId'], 'userId=', params['userId'], 'sns_friends=', sns_friends_param) # if sns_friends != '': # sns_friends = AccountVerify.decode_item(contacts) sns_friends = json.loads(sns_friends_param) Friend.mergeSnsFriends(params['appId'], params['userId'], sns_type, sns_friends, mo) mo.setResult('code', 0) mo.setResult('info', 'success') return mo
def jsonApiIntercept(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) return isReturn, params
def checkAccount(cls, rpath): return AccountCheck.normal_check(rpath, False)
def submitPushToken(cls, rpath): rparams = TyContext.RunHttp.convertArgsToDict() clientId = rparams.get('clientId', '') clientVersion = TyContext.ClientUtils.getVersionFromClientId(clientId) if clientVersion < 3.77: url = TyContext.Configure.get_global_item_str('push.server', '') else: url = TyContext.Configure.get_global_item_str( 'push.server.new', '') mo = TyContext.Cls_MsgPack() if url == '': mo.setResult('code', 0) mo.setResult('info', 'push server is null') return mo if clientVersion >= 3.77: # 都从SDK发出来,校验HTTP数据的安全性,校验code isReturn, params = AccountCheck.normal_check(rpath, False) if isReturn: return params url += '/push_register' postdata = urllib.urlencode(rparams) TyContext.ftlog.debug('updateToken 1 url=', url, 'rparams:', rparams, 'postdata:', postdata) response, url = TyContext.WebPage.webget(url, {}, None, postdata) code = 1 try: datas = json.loads(response) code = datas['code'] except: TyContext.ftlog.error('updateToken 1 return ERROR, response=', response) if code == 200: mo.setResult('code', 0) mo.setResult('info', 'success') else: mo.setResult('code', 1) mo.setResult('info', 'fail') return mo else: # url = 'http://127.0.0.1:8080/token/update' # url = 'http://125.39.218.101:8080/push/updateToken' m = re.search('0\-hall(\d+)', clientId) if m: appId = m.group(1) else: appId = '9999' TyContext.RunHttp.set_request_arg("appId", appId) TyContext.RunHttp.set_request_arg("imei", 'null') isReturn, params = AccountCheck.normal_check(rpath, False) if isReturn: return params url += '/push/updateToken' params = TyContext.RunHttp.convertArgsToDict() postdata = urllib.urlencode(params) TyContext.ftlog.debug('updateToken url=', url, 'postdata:', postdata) response, url = TyContext.WebPage.webget(url, {}, None, postdata) ec = 1 try: datas = json.loads(response) ec = datas['ec'] except: TyContext.ftlog.error('updateToken return ERROR, response=', response) if ec == 0: mo.setResult('code', 0) mo.setResult('info', 'success') else: mo.setResult('code', 1) mo.setResult('info', 'fail') return mo
def doIosCallback(cls, rpath): platformOrderId = TyContext.RunHttp.getRequestParam('iosOrderId', '') TyContext.RunMode.get_server_link(platformOrderId) isReturn, params = AccountCheck.normal_check(rpath, True) if isReturn: return params userId = params['userId'] appId = params['appId'] clientId = params['clientId'] appInfo = TyContext.RunHttp.getRequestParam('appInfo', '') isMock = bool(TyContext.RunHttp.getRequestParam('isMock')) receipt = TyContext.RunHttp.getRequestParam('receipt', '') receiptData = {'receiptJsonStr': '{"receipt-data" : "' + receipt + '"}', 'platformOrder': platformOrderId, 'userId': userId} TyContext.ftlog.info('IOS->doIosCallback->userId', userId, 'appId', appId, 'clientId', clientId, 'appInfo', appInfo, 'platformOrderId', platformOrderId, 'receipt', receipt, 'isMock', isMock) rparam = PayHelperV4.getArgsDict() rparam['chargeType'] = 'tuyooios' rparam['userId'] = params['userId'] rparam['appId'] = params['appId'] rparam['clientId'] = params['clientId'] isSandbox = is_sandbox_receipt(receipt) ret = cls.doIosCallbackVerify(receiptData, isSandbox, isMock) TyContext.ftlog.debug('IOS->doIosCallback->doIosCallbackVerify ret=', ret) if ret != 'ok' and ret != 'uuid_prohibit': PayHelperV4.callback_error(platformOrderId, ret, rparam) return ret # 如果是被封禁的uuid,不进行发货处理 if ret == 'uuid_prohibit': return 'success' transaction_id = receiptData['original_transaction_id'] rparam['third_orderid'] = transaction_id rparam['third_prodid'] = receiptData.get('product_id', 'na') rparam['isTestOrder'] = receiptData.get('sandbox', False) if cls._is_ios_transaction_delivered(transaction_id): PayHelperV4.callback_error(platformOrderId, 'error-transaction-already-delivered', rparam) TyContext.ftlog.info('IOS->doIosCallback error-transaction-already-delivered ' 'userId', userId, 'platformOrder', platformOrderId) return 'error-transaction-already-delivered' if not platformOrderId: ret = cls._deliver_missing_order(rparam) if not ret: return 'error-platform-order-missing' else: platformOrderId = ret # 根据商品Id过滤刷单的订单---------------start try: chargeKey = 'sdk.charge:' + platformOrderId chargeInfo = TyContext.RedisPayData.execute('HGET', chargeKey, 'charge') if chargeInfo == None: TyContext.ftlog.info('IOS->doIosCallback error-platformOrderId-not-found ' 'userId', userId, 'platformOrder', platformOrderId) return 'error-platform-order-missing' chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True) if 'chargeData' in chargeInfo and 'orderIosCode' in chargeInfo['chargeData'] and chargeInfo['chargeData'][ 'orderIosCode'] != rparam['third_prodid']: TyContext.ftlog.info('IOS->doIosCallback error-product_id ' 'userId', userId, 'platformOrder', platformOrderId, 'orderIosCode', chargeInfo['chargeData']['orderIosCode'], 'receipt_product_id', rparam['third_prodid']) return 'error-product_id' except: pass product = cls.get_pay_ios_product(appId, rparam['third_prodid'], clientId, 'iosid') if not product: TyContext.ftlog.error('get_pay_ios_product products not found!' ' appId=', appId, 'iosId=', rparam['third_prodid'], 'clientId=', clientId, 'checkIdKey=iosid') return 'error-product_id' # 根据商品Id过滤刷单的订单---------------end isOk = PayHelperV4.callback_ok(platformOrderId, -1, rparam) if isOk: cls._mark_ios_transaction_as_delivered(transaction_id) try: # 328 & 628 第一次购买后只能使用微信支付 ios_control = TyContext.Configure.get_global_item_json('ios_weinxin_pay_control', {}) if product['tyid'] in ios_control.get('weixin_products', []): wxpay_count = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'wxpay_flag') if not wxpay_count: wxpay_count = 0 TyContext.RedisUser.execute(userId, 'HSET', 'user:'******'wxpay_flag', int(wxpay_count) + 1) except: TyContext.ftlog.exception() return 'success' else: return 'error-handle-callback'
def doGoogleIABCallback(cls, rpath): action = TyContext.RunHttp.getRequestParam('action', '') appId = TyContext.RunHttp.getRequestParam('appId') clientId = TyContext.RunHttp.getRequestParam('clientId') # google支付需要向客户端返回公钥 publicKey = cls._get_google_public_key(appId, clientId, 'google_publickeys', clientId) TyContext.ftlog.debug('doGoogleIABCallback->action=', action, 'appId=', appId) result = {} if not action or action == '': result['action'] = '' result['state'] = 'error' result['info'] = 'error-action is null' return cls._dict2string(result) elif action == 'getKey': result['action'] = 'getKey' if publicKey == '': result['state'] = 'error' result['info'] = 'error-get publickey failed' return cls._dict2string(result) else: result['state'] = 'success' result['publicKey'] = publicKey result['info'] = 'get publickey success' return cls._dict2string(result) else: platformOrderId = TyContext.RunHttp.getRequestParam( 'platformOrderId', '') result['platformOrderId'] = platformOrderId if action == 'redelivery': result['action'] = 'redilivery' elif action == 'verify': result['action'] = 'verify' isReturn, params = AccountCheck.normal_check(rpath, True) if isReturn: result['state'] = 'error' result['info'] = 'error-accountcheck failed' TyContext.ftlog.error( 'doGoogleIABCallback->accountcheck failed:', params) return cls._dict2string(result) if not platformOrderId or platformOrderId is '': result['state'] = 'error' result['info'] = 'error-null platformOrderId' TyContext.ftlog.error( 'doGoogleIABCallback error platformOrderId is null') return cls._dict2string(result) signData = TyContext.RunHttp.getRequestParam( 'purchaseData', '') signature = TyContext.RunHttp.getRequestParam( 'dataSignature', '') TyContext.ftlog.info( 'TuyouPayGoogleIAB.doGoogleIABCallback->action=', action, 'platformOrderId=', platformOrderId, 'appId=', appId, 'signData=', signData, 'signature=', signature) base64PublicKey = '-----BEGIN PUBLIC KEY-----' + '\n' + publicKey + '\n' + '-----END PUBLIC KEY-----' if False and cls.doGoogleIABCallbackVerify( base64PublicKey, signData, signature) != True: result['state'] = 'error' result['info'] = 'error-verify failed' return cls._dict2string(result) if cls._is_google_transaction_delivered(platformOrderId): result['state'] = 'success' result['info'] = 'transaction-already-delivered' TyContext.ftlog.error( 'doGoogleIABCallback->order is already-delivered:', platformOrderId) return cls._dict2string(result) rparam = PayHelper.getArgsDict() rparam['chargeType'] = 'googleiab' isOk = PayHelper.callback_ok(platformOrderId, -1, rparam) if isOk: cls._mark_google_transaction_as_delivered(platformOrderId) result['state'] = 'success' result['info'] = 'googleiab callback success' return cls._dict2string(result) else: result['state'] = 'error' result['info'] = 'error-delivery' TyContext.ftlog.error('doGoogleIABCallback error delivery') return cls._dict2string(result)