Пример #1
0
def 微信预约发送短信(request):
    try:
        手机号 = str(request.GET['手机号'])
        if 手机号 == '':
            # return HttpResponse("手机号为空")
            response = HttpResponse('手机号为空')
        else:
            import random
            j = 6
            验证码 = ''.join(str(i) for i in random.sample(range(
                0, 9), j))  # sample(seq, n) 从序列seq中选择n个随机且独立的元素;
            __business_id = uuid.uuid1()
            params = "{\"code\":\"" + 验证码 + "\"}"
            from mysite.demo_sms_send import send_sms
            r = send_sms(__business_id, 手机号, myConfig.sign_name,
                         myConfig.template_code, params)
            r2 = json.loads(r)
            if r2['Code'] == 'OK':
                r = models.微信预约验证码表(验证码=验证码, 手机号=手机号).save()
                response = HttpResponse('短信发送成功')
            response = HttpResponse('请输入正确的手机号')
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "*"
        return response
    except:
        import traceback
        print(traceback.format_exc())
        response = HttpResponse('系统故障')
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "*"
        return response
Пример #2
0
def 订餐提醒任务():
    try:
        日期 = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        订餐提醒短信锁_first = 订餐提醒短信锁.objects(日期=日期).first()
        if 订餐提醒短信锁_first == None:
            订餐提醒短信锁(日期=日期, 短信锁=False).save()
            订餐提醒任务()
        else:
            if 订餐提醒短信锁_first.短信锁:
                return False
            else:
                订餐提醒短信锁_first.update(短信锁=True)
                template_code_ding_can_ti_xing = 'SMS_157682401'
                日期 = time.strftime('%Y-%m-%d',
                                   time.localtime(time.time() + 86400))
                订餐结果表_objs = 订餐结果表.objects(用餐日期=日期)
                手机号_list = []
                手机号_list.append('13305669898')  #这个用户要求屏蔽短信提醒
                for 订餐结果表_obj in 订餐结果表_objs:
                    if 订餐结果表_obj.中餐食堂就餐预订数 == 1 or 订餐结果表_obj.晚餐食堂就餐预订数 == 1:
                        手机号_list.append(订餐结果表_obj.手机号)
                订餐主界面表_objs = 订餐主界面表.objects
                for 订餐主界面表_obj in 订餐主界面表_objs:
                    手机号 = 订餐主界面表_obj.手机号
                    if 手机号 in 手机号_list:
                        pass
                    else:
                        # 创建时间 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
                        # print(创建时间, '发送订餐提醒短信给', 手机号)
                        __business_id = uuid.uuid1()
                        name = 订餐主界面表_obj.姓名
                        params = {'name': name, 'time': 日期}
                        params = json.dumps(params).encode('utf-8').decode(
                            'unicode_escape')
                        r = send_sms(__business_id, 手机号, sign_name,
                                     template_code_ding_can_ti_xing, params)
                        r2 = json.loads(r)
                        if r2['Code'] == 'OK':
                            创建时间 = time.strftime('%Y-%m-%d %H:%M:%S',
                                                 time.localtime(time.time()))
                            print(创建时间, '发送订餐提醒短信给', 手机号)
                return True
    except:
        print(traceback.format_exc())
        return False
Пример #3
0
def 销售发送验证码(request):
    try:
        手机号 = str(request.GET['phone'])
        if 手机号 == '':
            return HttpResponse("手机号为空")
        else:
            import random
            j = 6
            验证码 = ''.join(str(i) for i in random.sample(range(
                0, 9), j))  # sample(seq, n) 从序列seq中选择n个随机且独立的元素;
            __business_id = uuid.uuid1()
            params = "{\"code\":\"" + 验证码 + "\"}"
            r = send_sms(__business_id, 手机号, sign_name, template_code, params)
            r2 = json.loads(r)
            if r2['Code'] == 'OK':
                r = 销售验证码表(验证码=验证码, 手机号=手机号).save()
            return HttpResponse(r2['Code'])
    except:
        return HttpResponse('500')
Пример #4
0
def send_sms(request):
    import json
    from . import models
    from django.http import HttpResponse
    import traceback
    import myConfig
    try:
        myVar1 = request.POST['userphone']
        qset1 = models.ji_li_zhu_shou_userinfo.objects(
            userphone=myVar1).first()
        if qset1 == None:
            response = HttpResponse(json.dumps({'code': '用户不存在'}))
        else:
            import random
            j = 6
            验证码 = ''.join(str(i) for i in random.sample(range(
                0, 9), j))  # sample(seq, n) 从序列seq中选择n个随机且独立的元素;
            import uuid
            __business_id = uuid.uuid1()
            params = "{\"code\":\"" + 验证码 + "\"}"
            from mysite.demo_sms_send import send_sms
            r = send_sms(__business_id, qset1.userphone, myConfig.sign_name,
                         myConfig.template_code, params)
            r2 = json.loads(r)
            if r2['Code'] == 'OK':
                qset1.update(userpwd=验证码)
                response = HttpResponse(json.dumps({'code': '成功'}))
            else:
                response = HttpResponse(json.dumps({'code': '号码不正确'}))
    except:
        response = HttpResponse(json.dumps({'code': '系统错误'}))
        import traceback
        print(traceback.format_exc())
    response["Access-Control-Allow-Origin"] = "*"
    response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
    response["Access-Control-Max-Age"] = "1000"
    response["Access-Control-Allow-Headers"] = "*"
    return response
Пример #5
0
def 提交办事申请(request):
    try:
        myState = str(request.GET['myState'])
        myState_json = json.loads(myState)
        access_token = myState_json['access_token']
        refresh_token = myState_json['refresh_token']
        qset0 = models.微信预约用户表.objects(refresh_token=refresh_token).first()
        if qset0 == None:
            response = HttpResponse('用户未注册')
        else:
            姓名 = myState_json['姓名']
            验证码 = myState_json['验证码']
            手机号 = myState_json['手机号']
            身份证号码 = myState_json['身份证号码']
            部门编号 = myState_json['部门编号']
            部门名称 = myState_json['部门名称']
            办事内容 = myState_json['办事内容']
            办事日期 = myState_json['办事日期']
            办事区间 = myState_json['办事区间']
            其它 = {}
            # 上午办事区间 = ['9:00-10:00','10:00-11:00','11:00-12:00']
            # 下午办事区间 = ['14:00-15:00','15:00-16:00','16:00-17:30']
            当前日期 = time.strftime('%Y-%m-%d', time.localtime(time.time()))
            当前日期第二天 = time.strftime('%Y-%m-%d',
                                    time.localtime(time.time() + 86400))
            当前日期五天后 = time.strftime('%Y-%m-%d',
                                    time.localtime(time.time() + 432000))
            当前小时 = time.strftime('%H:%M:%S', time.localtime(time.time()))
            # 办事日期 = '2019-11-09'
            # 当前日期第二天 = '2019-11-09'
            # 当前小时 = '18:00:00'
            if 办事日期 == '':
                response = HttpResponse('办事日期为空,请重新输入')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response
            if 办事区间 == '':
                response = HttpResponse('办事区间为空,请重新输入')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response
            if 办事内容 == '':
                response = HttpResponse('办事内容为空,请重新输入')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response
            if 办事日期 < 当前日期:
                response = HttpResponse('办事日期已过,请重新输入')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response
            if 办事日期 == 当前日期:
                # if 当前小时 <= '12:00:00':
                #     if 办事区间 in 上午办事区间:
                #         response = HttpResponse('请选择下午办事')
                #         response["Access-Control-Allow-Origin"] = "*"
                #         response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                #         response["Access-Control-Max-Age"] = "1000"
                #         response["Access-Control-Allow-Headers"] = "*"
                #         return response
                # if 当前小时 > '12:00:00':
                #     response = HttpResponse('请选择明天办事')
                #     response["Access-Control-Allow-Origin"] = "*"
                #     response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                #     response["Access-Control-Max-Age"] = "1000"
                #     response["Access-Control-Allow-Headers"] = "*"
                #     return response
                response = HttpResponse('请选择明天办事')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response
            if 办事日期 >= 当前日期五天后:
                response = HttpResponse('请选择最近5天预约')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response
            if 是否工作日(办事日期):
                response = HttpResponse('请选择非工作日预约!')
                response["Access-Control-Allow-Origin"] = "*"
                response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                response["Access-Control-Max-Age"] = "1000"
                response["Access-Control-Allow-Headers"] = "*"
                return response

            if 办事日期 == 当前日期第二天:
                if 是否工作日(办事日期):
                    pass
                else:
                    if 当前小时 > '17:00:00':
                        response = HttpResponse('已超过下午5点,请改天预约!')
                        response["Access-Control-Allow-Origin"] = "*"
                        response[
                            "Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
                        response["Access-Control-Max-Age"] = "1000"
                        response["Access-Control-Allow-Headers"] = "*"
                        return response

            qset1 = models.微信预约用户表.objects(refresh_token=refresh_token,
                                           手机号=手机号).first()
            if qset1 == None:
                response = HttpResponse('未绑定手机')
            else:
                qset2 = models.微信预约办事申请表.objects(openid=qset1.openid,
                                                 部门编号=部门编号,
                                                 部门名称=部门名称,
                                                 办事日期=办事日期).first()
                if qset2 == None:
                    models.微信预约办事申请表(openid=qset1.openid,
                                     部门编号=部门编号,
                                     部门名称=部门名称,
                                     办事内容=办事内容,
                                     办事日期=办事日期,
                                     办事区间=办事区间,
                                     其它=其它).save()
                    res = '预约成功'
                else:
                    qset2.update(部门编号=部门编号,
                                 部门名称=部门名称,
                                 办事内容=办事内容,
                                 办事日期=办事日期,
                                 办事区间=办事区间,
                                 其它=其它)
                    res = '更新预约成功'
                __business_id = uuid.uuid1()
                # params = {'riqi':办事日期,'qujian':办事区间,'banshi':办事内容}
                params = "{\"riqi\":\"" + "\",\"qujian\":\"" + "\",\"banshi\":\"" + 部门名称 + "\"}"
                from mysite.demo_sms_send import send_sms
                print(手机号, myConfig.sign_name, myConfig.template_code_dzzwzx,
                      params)
                r = send_sms(__business_id, 手机号, myConfig.sign_name,
                             myConfig.template_code_dzzwzx, params)
                r2 = json.loads(r)
                print(r2)
                if r2['Code'] == 'OK':
                    response = HttpResponse(res + ',短信发送成功')
                else:
                    response = HttpResponse(res + ',短信发送失败')
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "*"
        return response
    except:
        import traceback
        print(traceback.format_exc())
        response = HttpResponse('系统故障')
        response["Access-Control-Allow-Origin"] = "*"
        response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
        response["Access-Control-Max-Age"] = "1000"
        response["Access-Control-Allow-Headers"] = "*"
        return response