def setUp(self): #连接account测试服务器 consulAccountHost = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServiceAddress') consulAccountPort = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServicePort') print(consulAccountHost + ':' + str(consulAccountPort)) accountChannel = grpc.insecure_channel(consulAccountHost + ':' + str(consulAccountPort)) self.accountStub = account_pb2_grpc.AccountSrvStub(accountChannel) #连接dealer测试服务器 http://10.1.0.4:8500 consulDealerHost = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServiceAddress') consulDealerPort = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServicePort') print(consulDealerHost + ':' + str(consulDealerPort)) dealerChannel = grpc.insecure_channel(consulDealerHost + ':' + str(consulDealerPort)) self.dealerStub = mt4dealer_pb2_grpc.MT4DealerSrvStub(dealerChannel)
def bindPico(UserID, group, IsTrader, accountType): # 连接account测试服务器 consulAccountHost = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServiceAddress') consulAccountPort = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServicePort') accountChannel = grpc.insecure_channel(consulAccountHost + ':' + str(consulAccountPort)) accountStub = account_pb2_grpc.AccountSrvStub(accountChannel) # 连接dealer测试服务器 http://10.1.0.4:8500 consulDealerHost = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServiceAddress') consulDealerPort = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServicePort') dealerChannel = grpc.insecure_channel(consulDealerHost + ':' + str(consulDealerPort)) dealerStub = mt4dealer_pb2_grpc.MT4DealerSrvStub(dealerChannel) bindPico = dealerStub.CreateAccount( mt4dealer_pb2.Account(Name='MAM_ACCOUNT_' + str(UserID), Password='******', BrokerID=1, Group=group, City='sz')) login = bindPico.Login # 将注册的用户提取到t_useraccount表 accountStub.SaveUserAccount( account_pb2.SaveUserAccountRequest( User=account_pb2.User(Id=UserID), BrokerID=1, MT4Account=str(login), IsTrader=IsTrader, AccountCreateType=0, IsBind=2, AccountType=accountType)) # pico入金 dealerStub.DepositWithdraw( mt4dealer_pb2.DepositWithdrawMessage( Login=login, Price=10000000, Comment='Deposit With script.')) return bindPico
def setUp(self): # 登录 datas = { "account": userData['waccount'], "password": userData['wpasswd'], "remember": "false" } traderLoginRes = Auth.signin( userData['hostName'] + userDataAuth['signin_url'], userData['headers'], datas) self.assertEqual(traderLoginRes.status_code, userData['status_code_200']) self.token = json.loads(traderLoginRes.text)['data']['token'] # 连接account测试服务器 consulAccountHost = FMCommon.consul_operater( host=userDatagrpc['consulHost'], port=userDatagrpc['consulPort'], server='followme.srv.account', key='ServiceAddress') consulAccountPort = FMCommon.consul_operater( host=userDatagrpc['consulHost'], port=userDatagrpc['consulPort'], server='followme.srv.account', key='ServicePort') accountChannel = grpc.insecure_channel(consulAccountHost + ':' + str(consulAccountPort)) self.accountStub = account_pb2_grpc.AccountSrvStub(accountChannel) print("self.accountStub:", self.accountStub) # 连接dealer测试服务器 http://10.1.0.4:8500 consulDealerHost = FMCommon.consul_operater( host=userDatagrpc['consulHost'], port=userDatagrpc['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServiceAddress') consulDealerPort = FMCommon.consul_operater( host=userDatagrpc['consulHost'], port=userDatagrpc['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServicePort') print(consulDealerHost + ':' + str(consulDealerPort)) dealerChannel = grpc.insecure_channel(consulDealerHost + ':' + str(consulDealerPort)) self.dealerStub = mt4dealer_pb2_grpc.MT4DealerSrvStub(dealerChannel) print("self.dealerStub:", self.dealerStub)
def registerByMobile(mobile,password,invite): # 连接account测试服务器 consulAccountHost = FMCommon.consul_operater(host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServiceAddress') consulAccountPort = FMCommon.consul_operater(host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServicePort') # print(consulAccountHost + ':' + str(consulAccountPort)) accountChannel = grpc.insecure_channel(consulAccountHost + ':' + str(consulAccountPort)) accountStub = account_pb2_grpc.AccountSrvStub(accountChannel) # 连接dealer测试服务器 http://10.1.0.4:8500 consulDealerHost = FMCommon.consul_operater(host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServiceAddress') consulDealerPort = FMCommon.consul_operater(host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServicePort') # print(consulDealerHost + ':' + str(consulDealerPort)) dealerChannel = grpc.insecure_channel(consulDealerHost + ':' + str(consulDealerPort)) dealerStub = mt4dealer_pb2_grpc.MT4DealerSrvStub(dealerChannel) # 获取图形验证码 captchaUrl = webApiData['hostName'] + userDataAuthUrl['getCaptcha_url'] user_token = Account.getTokenForCaptcha(captchaUrl) header = {'content-type': 'application/json', 'Authorization': 'Bearer ' + str(user_token)} # 读取图形验证码 ccap = Account.getCaptchaForRedis(user_token) # 根据图形验证码获取短信验证码 smsUrl = webApiData['hostName'] + userDataAuthUrl['getSMSScode_url'] + mobile + '&captcha=' + ccap # print(smsUrl) '''获取短信验证码成功''' smsCode = Account.getSMSCodeForRedis(smsUrl, headers=header, userToken=str(user_token),registerAccount=mobile) # 注册 url = webApiData['hostName'] + userDataAuthUrl['register_url'] res = Auth.register(url, headers=header, account=mobile, password=password, platform=webApiData['platform'], captcha=str(ccap), smscode=smsCode, invite=invite, oauth2=webApiData['oauth2']) # 请求成功,返回200 ok userID = json.loads(res.text)["data"]["id"] # 设置用户昵称 setNickName = accountStub.SetNickName(account_pb2.User(Id=userID, NickName="ciStar"+str(userID))) # 检查设置成功后,返回值为:0 return userID
def getCachedUserById(channel): stub = account_pb2_grpc.AccountSrvStub(channel) response = stub.GetCachedUserById(account_pb2.User(Id=2)) print("============Greeter client received: " + response.User.AccountEmail)
def RegisterByEmail(): ##alibeta 环境连接信息 ++++++++++++++++++++++++++++++++ #连接account测试服务器 consulAccountHost = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServiceAddress') consulAccountPort = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.account', key='ServicePort') accountChannel = grpc.insecure_channel(consulAccountHost + ':' + str(consulAccountPort)) accountStub = account_pb2_grpc.AccountSrvStub(accountChannel) #连接dealer测试服务器 http://10.1.0.4:8500 consulDealerHost = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServiceAddress') consulDealerPort = FMCommon.consul_operater( host=userData['consulHost'], port=userData['consulPort'], server='followme.srv.copytrade.dealer.pico', key='ServicePort') # print(consulDealerHost + ':' + str(consulDealerPort)) dealerChannel = grpc.insecure_channel(consulDealerHost + ':' + str(consulDealerPort)) mt4dealer_pb2_grpc.MT4DealerSrvStub(dealerChannel) accountEmail = 'test' + str(int(time.time())) + '@followme-inc.com' userPassword = '******' nickName = 'Demo' + str(int(time.time())) print(nickName) # 注册一个测试账号 register = accountStub.RegisterByEmail( account_pb2.RegisterUserRequest(User=account_pb2.User( AccountEmail=accountEmail, UserPassword=userPassword))) # #断言帐号状态为5,未激活 # #AccountStatus: 0 新申请, 1 审核中, 2 正常, 3 锁定(此时交易员才可提取服务费), 4 注销, 5 未激活,6 注销 userID = register.Id #新注册的账号需要先激活才能登录 #发送验证码邮件到邮箱 accountStub.SendActivationEmail( account_pb2.SendActivationEmailRequest( UserId=userID, ActivationCode='thisisactivationcode', Email='*****@*****.**', Subject='注册followme验证码')) #获取验证码 getActivationByObj = accountStub.GetActivationByObj( account_pb2.ActivationRequest(ObjectId=userID)) vercode = getActivationByObj.VerCode activationCode = getActivationByObj.ActivationCode #激活账号。 #AccountStatus: 0 新申请, 1 审核中, 2 正常, 3 锁定(此时交易员才可提取服务费), 4 注销, 5 未激活,6 注销 accountStub.ValidateEmailLink( account_pb2.ValidateEmailLinkRequest(UserId=userID, VerCode=vercode, ActivationCode=activationCode, Token=str(uuid.uuid1()))) #设置用户昵称 accountStub.SetNickName(account_pb2.User(Id=userID, NickName=nickName)) return accountEmail