def call_robot(src_uid): '''{"doc":"agora/early_test.md"} ### 直接拨打机器 直接拨打机器人,演示用 废弃[2020/2/12] ''' appID = settings.AGORA.get('appID') appCertificate = settings.AGORA.get('appCertificate') channelName = 'ch_' + get_str(length=10) userAccount = src_uid Role_Attendee = 2 privilegeExpiredTs = time.time() + 600 token = RtcTokenBuilder.buildTokenWithAccount(appID, appCertificate, channelName, userAccount, Role_Attendee, privilegeExpiredTs) general_log.info('[%s]向机器人拨打语音' % src_uid) #send_mp3(channelName,mp3_url='/static/Haydn_Cello_Concerto_D-1.mp3') send_mp3(channelName, mp3_url='/static/tts.mp3') return { 'appID': appID, 'channel': channelName, 'uid': userAccount, 'token': token, }
def call_user(src_uid, dst_uid=None, extra_msg='', call_group=0): '''{'doc':'api/call.md',} ### 拨打 用户拨打电话给其他人 @dst_uid:list ''' from maindb.tasks import push_apple_message if isinstance(dst_uid, str): dst_uid = dst_uid.split(',') appID = settings.AGORA.get('appID') appCertificate = settings.AGORA.get('appCertificate') channelName = 'ch_' + get_str(length=10) userAccount = src_uid Role_Attendee = 2 privilegeExpiredTs = time.time() + 600 token = RtcTokenBuilder.buildTokenWithAccount(appID, appCertificate, channelName, userAccount, Role_Attendee, privilegeExpiredTs) general_log.info('[%s]向[%s]拨打语音;channel=%s' % (src_uid, dst_uid, channelName)) sim_signal.send('call.call', uid=src_uid, channel=channelName, src_uid=src_uid, dst_uid=dst_uid, extra_msg=extra_msg, is_robot=False, call_group=call_group) if dst_uid: for uid in dst_uid: sim_signal.send('call.call', uid=uid, channel=channelName, src_uid=src_uid, dst_uid=dst_uid, extra_msg=extra_msg) #VoiceMsgList.objects.create(uid = uid,channel=channelName,extra_msg=extra_msg) users = Accountinfo.objects.filter(uid__in=dst_uid).exclude( apns_token="") for user in users: infodc = { 'title': 'audiocall', 'accountCaller': src_uid, 'channel': channelName, } push_apple_message.delay(user.apns_token, infodc, src_uid) #VoiceCallPush(user.apns_token, infodc,src_user = src_uid).push() return { 'appID': appID, 'channel': channelName, 'uid': userAccount, 'token': token, }
def call_user(src_uid, dst_uid, taskid): ''' 机器人主动拨打电话给用户 @dst_uid:list ''' channelName = 'ch_' + get_str(length=10) general_log.info('机器人主动拨打任务 taskid=%s;src_uid=%s;dst_uid=%s;channel=%s' % (taskid, src_uid, dst_uid, channelName)) robot_call_user(src_uid, dst_list=dst_uid, channel_name=channelName, taskid=taskid) sim_signal.send('call.call', uid=src_uid, channel=channelName, src_uid=src_uid, dst_uid=dst_uid, extra_msg='', is_robot=True) if dst_uid: for uid in dst_uid: #VoiceMsgList.objects.create(uid = uid,channel=channelName,extra_msg=extra_msg) extra_msg_dc = { 'Subscribers': dst_uid, 'CallerId': src_uid, 'Type': 1, 'robot': True } extra_msg = json.dumps(extra_msg_dc, ensure_ascii=False) sim_signal.send('call.call', uid=uid, channel=channelName, src_uid=src_uid, dst_uid=dst_uid, extra_msg=extra_msg, is_robot=True) dc = { "title": "audiocall", "accountCaller": src_uid, "channel": channelName, "accountRemote": uid, } if len(dst_uid) >= 1: dc['extra_msg'] = dst_uid send_msg(json.dumps(dc, ensure_ascii=False), uid) users = Accountinfo.objects.filter(uid__in=dst_uid).exclude( apns_token="") for user in users: infodc = { 'title': 'audiocall', 'accountCaller': src_uid, 'channel': channelName, } push_apple_message.delay(user.apns_token, infodc, src_uid)
def create_user_profile(sender, instance, created, **kwargs): if created: invite_code = get_str(length=6).lower() UserInfo.objects.create(user=instance, invite_code=invite_code) #@receiver(post_save, sender=User) #def save_user_profile(sender, instance, **kwargs): #instance.profile.save()
def after_save(self): if not self.instance.regist_code: for i in range(50): # 重试50次来写入 , 应该不会有问题了 regist_code = get_str(4) count = AgentUser.objects.filter(pk=self.instance.pk).exclude( regist_code=regist_code).update(regist_code=regist_code) if count >= 1: self.instance.refresh_from_db() break
def clean_save(self): user = self.instance user.set_password(self.kw.get('password')) user.is_active = True invite_code = get_str(length=6).lower() UserInfo.objects.create(user=user, phone=self.kw.get('phone'), nickname=self.kw.get('nickname', ''), invite_code=invite_code, invite_by=self.invite_user)
def pre_save(self, model_instance, add): """ Returns field's value just before saving. """ if getattr(model_instance, self.name, '') == '': while True: char_id = get_str(length=self.char_len) dc = {self.name: char_id} if not model_instance._meta.model.objects.filter( **dc).exists(): setattr(model_instance, self.name, char_id) break return super().pre_save(model_instance, self.attname)
def clean_dict(self, dc): dc['username'] = "******" % (get_str(6), abs(hash(timezone.now))) return dc
def make_phone_validate_code(phone, length=6): code = get_str(length) PhoneCode.objects.create(code=code, valid=True, phone=phone) return code