Exemplo n.º 1
0
def SendUserOvertimeMsg(request):
    try:
        appid = "wx457b9d0e6f93d1c5"
        overtime_days1 = OVERTIMEDAYS - 7
        overtime_days2 = OVERTIMEDAYS - 30
        params = json.loads(request.raw_post_data)
        #params = request.GET
        wxuser_id = int(params.get('wxuser_id', 0))
        overtime_date = (datetime.datetime.now() - datetime.timedelta(
            days=overtime_days1)).strftime("%Y-%m-%d 00:00:00")
        overtimepoint = 0
        overtimepoint_details = UserPointDetail.objects.filter(
            wxUserID=wxuser_id, Created__lt=overtime_date, IsHandled=0)
        if overtimepoint_details:
            for detail in overtimepoint_details:
                overtimepoint += detail.Points - detail.SpentPoints
            if overtimepoint > 0:
                wxuser = wxUser.objects.get(ID=wxuser_id)
                wxserviceuser = wxUser.objects.filter(SourceAccount=appid,
                                                      unionID=wxuser.unionID)
                if wxserviceuser:
                    wxObj = wxAccountInterface.wxAccountInterface(appid)
                    wxObj.SendPointOvertimeRemindTemplate(
                        wxserviceuser[0].Name, overtimepoint, 7,
                        wxserviceuser[0].openID)
                Send106txtTelMsg(
                    wxuser.Mobile,
                    "【外滩教育】尊敬的外滩教育小主,您有%d奖学金将于7天内过期,现外滩教育推出了系列精品优惠好课,您可以在小程序中查看奖学金情况。奖学金购课可以抵现哦,赶快来看看吧~"
                    % overtimepoint, 0)
                Log(
                    "Point SendUserOvertimeMsg userid:7 %d;  points: %d" %
                    (wxuser_id, overtimepoint), "local", "0.0.0.0", "DEBUG")
        else:
            overtime_date = (datetime.datetime.now() - datetime.timedelta(
                days=overtime_days2)).strftime("%Y-%m-%d 00:00:00")
            overtimepoint_details = UserPointDetail.objects.filter(
                wxUserID=wxuser_id, Created__lt=overtime_date, IsHandled=0)
            for detail in overtimepoint_details:
                overtimepoint += detail.Points - detail.SpentPoints
            if overtimepoint > 0:
                wxuser = wxUser.objects.get(ID=wxuser_id)
                wxserviceuser = wxUser.objects.filter(SourceAccount=appid,
                                                      unionID=wxuser.unionID)
                if wxserviceuser:
                    wxObj = wxAccountInterface.wxAccountInterface(appid)
                    wxObj.SendPointOvertimeRemindTemplate(
                        wxserviceuser[0].Name, overtimepoint, 30,
                        wxserviceuser[0].openID)
                Send106txtTelMsg(
                    wxuser.Mobile,
                    "【外滩教育】尊敬的外滩教育小主,您有%d奖学金将于30天内过期,现外滩教育推出了系列精品优惠好课,您可以在小程序中查看奖学金情况。奖学金购课可以抵现哦,赶快来看看吧~"
                    % overtimepoint, 0)
                Log(
                    "Point SendUserOvertimeMsg userid:30 %d;  points: %d" %
                    (wxuser_id, overtimepoint), "local", "0.0.0.0", "DEBUG")
        return HttpResponse('ok')
    except Exception, e:
        Log("Point SendUserOvertimeMsg error: %s" % e, "local", "0.0.0.0",
            "DEBUG")
        return HttpResponse(e)
Exemplo n.º 2
0
def TemplateMsgTask(request):
    try:
        params = json.loads(request.raw_post_data)
        Log("TemplateMsgTask ", Type="DEBUG")
        keys = [
            'first', 'remark', 'keyword1', 'keyword2', 'keyword3', 'keyword4',
            'keyword5', 'keyword6'
        ]

        Log("TemplateMsgTask params %s" % params, Type="DEBUG")
        openid = params.get('openid')
        msg_info_id = params.get('msg_info_id')

        Log("TemplateMsgTask openid %s" % openid, Type="DEBUG")
        template_id = params.get('template_id')
        appid = "wx457b9d0e6f93d1c5"
        wxObj = wxAccountInterface.wxAccountInterface(appid)
        paraDic = {}
        paraDic["url"] = params.get('url')
        for key in keys:
            if params.has_key(key):
                paraDic[key] = params[key]  #.replace("{username}", user.Name)
        res = wxObj.CallCustomerTemplateMessage(template_id, openid, paraDic,
                                                msg_info_id)
        Log("TemplateMsgTask res: %s" % res, Type="DEBUG")
        return HttpResponse(res)
    except Exception, e:
        Log("TemplateMsgTask error: %s" % e, Type="DEBUG")
        return HttpResponse(e)
Exemplo n.º 3
0
 def GetwxAccountInterface(self, authorizer_appid):
     try:
         wxObj = wxAccountInterface.wxAccountInterface(authorizer_appid)
         return wxObj
     except Exception, e:
         Log("Error when GetwxAccountInterface: %s" % e)
         return None
Exemplo n.º 4
0
def GetAccountTemplates(request):
    try:
        updateVar('AllWxAcounts')
        appid = "wx457b9d0e6f93d1c5"
        wxObj = wxAccountInterface.wxAccountInterface(appid)
        res = wxObj.GetAccountTemplates()
        return HttpResponse(json.dumps(res))
    except Exception, e:
        Log("GetAccountTemplates error:%s" % e, "local", "0.0.0.0", "DEBUG")
        return HttpResponse(e)
Exemplo n.º 5
0
def GetQRCode(request):
    try:
        params = request.GET
        code = params.get('code')
        appid = "wx457b9d0e6f93d1c5"
        #Log("GetQRCode code:%s"%code, "local", "0.0.0.0", "DEBUG")
        wxObj = wxAccountInterface.wxAccountInterface(appid)
        res = wxObj.GetQRCode(code)
        return HttpResponse(res)
    except Exception, e:
        Log("GetQRCode error: %s" % e, Type="DEBUG")
        return HttpResponse(None)
Exemplo n.º 6
0
def LessonRemindASYNC(request):
    try:
        appid = "wx457b9d0e6f93d1c5"
        wxObj = wxAccountInterface.wxAccountInterface(appid)
        params = json.loads(request.raw_post_data)
        name = params.get("Name")
        cloud_course_id = int(params.get("CloudCourseID"))
        start_time = params.get("StartTime")
        is_daily = int(params.get("IsDaily"))
        course = CloudCourse.objects.get(ID=cloud_course_id)
        course = CloudCourse.objects.get(ID=cloud_course_id)
        students = CloudCourseMember.objects.filter(
            CloudCourseID=cloud_course_id, IsHide=0)
        for student in students:
            course_name = course.Name.replace("【", "[").replace("】", "]")
            if student.Role == 0:
                wxuser = wxUser.objects.values(
                    'openID', 'Name').filter(Mobile=student.Mobile)
                #if is_daily == 1:
                countent = "【外滩教育】 %s,您报名的 %s 课程将于 %s 开始上课,请您在PC上打开上课网址:class.ddianke.com,请合理安排时间,不要错过。感谢您对外滩的支持与信任,如有疑问,请在学习社群内咨询老师。" % (
                    student.Name, course_name, start_time)
                Send106txtTelMsg(student.Mobile, countent, 1)
                if not wxuser:
                    continue
                name = student.Name
                if not name:
                    name = wxuser[0]['Name']
                wxObj.SendClassRemindTemplate(name, course.Name, start_time,
                                              wxuser[0]['openID'])
            else:
                wxuser = wxUser.objects.values(
                    'openID', 'Name').filter(Mobile=student.Mobile)
                #if is_daily == 1:
                countent = "【外滩教育】 %s,您负责的课程 %s 课程将于 %s 开始上课,请您在PC上打开上课网址:class.ddianke.com,请确认上课时间。如有变动,请及时联系外滩工作人员,感谢您的支持。" % (
                    student.Name, course_name, start_time)
                Send106txtTelMsg(student.Mobile, countent, 1)
                if not wxuser:
                    continue
                name = student.Name
                if not name:
                    name = wxuser[0]['Name']
                wxObj.SendTeacherClassRemindTemplate(name, course.Name,
                                                     start_time,
                                                     wxuser[0]['openID'])
    except Exception, e:
        Log("LessonRemindASYNC error: %s" % e, Type="DEBUG")
        return HttpResponse([])
Exemplo n.º 7
0
    def GetAuthInfo(self, strAuthCode):

        try:
            token = self.GetAccessToken()
            url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%s" % token
            values = {
                "component_appid": self.appId,
                "authorization_code": strAuthCode
            }
            Log("GetAuthInfo Started!")
            res = Post(url, values)
            Log("Result:%s" % res)
            authorization_info = json.loads(res)["authorization_info"]
            authorizer_appid = authorization_info["authorizer_appid"]
            authorizer_access_token = ""
            authorizer_refresh_token = ""
            wxObj = wxAccountInterface.wxAccountInterface(authorizer_appid)
            wxObj.UpdateAuthinfo(authorization_info)
            return wxObj
        except Exception, e:
            Log("Error when GetAuthInfo: %s" % e)
            return None
Exemplo n.º 8
0
def SendTemplateMessage(request):
    try:
        keys = [
            'first', 'remark', 'keyword1', 'keyword2', 'keyword3', 'keyword4',
            'keyword5', 'keyword6'
        ]
        rd_url = "http://applinzi.ddianke.com/wxJSWeb/read_count?msg_info_id=%d"
        params = request.POST
        openids = params.get('openids')
        unionid = params.get('unionid')
        token = params.get('token', None)

        template_id = params.get('template_id')
        #Log("SendTemplateMessage params: %s" % params, "local", "0.0.0.0", "DEBUG")
        appid = "wx457b9d0e6f93d1c5"
        wxObj = wxAccountInterface.wxAccountInterface(appid)
        if unionid:
            openids = []
            user = wxUser.objects.filter(unionID=unionid, SourceAccount=appid)
            if user:
                openids.append(user[0].openID)
        else:
            openids = openids.split(',')

        url = params.get('url', None)
        msg_info_id = 0

        #不再需要openid去重
        if token != 'test':
            dic = {}
            for key in keys:
                if params.has_key(key):
                    dic[key] = params[key]
            #(msg_info_id, openids) = GetMessageOpenids(token, openids, json.dumps(dic), url)
            msg_info_id = AddMessageInfo('template', json.dumps(dic), openids,
                                         token, url)
        #else:
        #    return HttpResponse('has no token')

        paraDic = {}
        if url:
            if msg_info_id:
                paraDic["url"] = rd_url % msg_info_id
            else:
                paraDic["url"] = url
            Log("SendTemplateMessage url: %s" % paraDic["url"], Type="DEBUG")
        paraDic["msg_info_id"] = msg_info_id
        paraDic["template_id"] = template_id

        users = wxUser.objects.values("Name",
                                      "openID").filter(openID__in=openids)
        queue = TaskQueue('queue_name')
        for user in users:
            for key in keys:
                if params.has_key(key):
                    paraDic[key] = params[key].replace("{username}",
                                                       user['Name'])
            task_url = "TemplateMsgTask/"
            paraDic["openid"] = user['openID']
            queue.add(Task(task_url, json.dumps(paraDic), delay=2))
            #wxObj.CallCustomerTemplateMessage(template_id, user['openID'], paraDic, msg_info_id)
        #UpdateSendResult(msg_info_id)
        #task_url = 'UpdateTemplateSendResult/'
        #queue.add(Task(task_url, json.dumps({"msg_info_id":msg_info_id}) ,delay=2))
        return HttpResponse('ok')
    except Exception, e:
        Log("SendTemplateMessage error:%s" % e, "local", "0.0.0.0", "DEBUG")
        return HttpResponse(e)