示例#1
0
    def get(self, company_id):
        if not company_id:
            return self.echo('view/login/404.html', layout='')

        company_db = CompanyServices(self.db)
        company = company_db.get_company_by_id(int(company_id))

        app_url = ''
        if company.Fapp_url:
            app_url = company.Fapp_url
        else:
            app_url = setting.WX_APP_URL + '/' + str(
                company.Fid)  #使用公司id作为app url的关键参数
            company_db.update_company_by_id(company.Fid, Fapp_url=app_url)

        app_token = ''
        if company.Fapp_token:
            app_token = company.Fapp_token
        else:
            uuid_str = uuid.uuid3(
                uuid.NAMESPACE_DNS,
                str(company.Fid) +
                str(company.Fuser_id))  #使用id+user_id生产uuid作为token
            app_token = str(uuid_str)
            app_token = app_token.replace('-', '')
            company_db.update_company_by_id(company.Fid, Fapp_token=app_token)

        self.echo('ops/weixin/detail.html', {
            'company': company,
            'app_url': app_url,
            'app_token': app_token,
        })
示例#2
0
    def post(self, company_id):
        rspDic = {}
        rspDic["stat"] = "ok"  #返回页面的字典,ok,fail
        rspDic["msg"] = ""

        if not company_id:
            rspDic["stat"] = "fail"
            rspDic["msg"] = u"公司不存在"
            return self.write(json.dumps(rspDic))

        try:
            company_db = CompanyServices(self.db)
            company = company_db.get_company_by_id(int(company_id))
            if company.Fmenu_codes:
                rspDic["stat"] = "fail"
                rspDic["msg"] = u"解除绑定前,请先解除菜单绑定!"
                return self.write(json.dumps(rspDic))

            dic_app = {}
            dic_app['Fapp_url'] = ''
            dic_app['Fapp_token'] = ''
            dic_app['Fapp_id'] = ''
            dic_app['Fapp_secret'] = ''

            company_db = CompanyServices(self.db)
            company_db.update_company_by_id(int(company_id), **dic_app)
        except Exception, e:
            rspDic["stat"] = "fail"
            rspDic["msg"] = u"微信删除失败"
示例#3
0
 def post(self, company_id,*args, **kwargs):
     rsg = {
         'stat':'err',
         'msg':''
     }
     self.get_paras_dict()
     if not self.qdict.get('Fcompany_name') or not self.qdict.get('Fdetail_address') or not self.qdict.get('nick_name') \
             or not self.qdict.get('user_mobi'):
         rsg['msg'] = '不能为空!'
         return self.write(ujson.dumps(rsg))
     company_service = CompanyServices(self.db)
     company_service.update_company_by_id(company_id,**self.qdict)
     rsg['stat'] = 'ok'
     return self.write(ujson.dumps(rsg))
示例#4
0
    def post(self, company_id):
        #界面参数解析
        self.get_paras_dict()

        rspDic = {}
        rspDic["stat"] = "ok"  #返回页面的字典,ok,fail
        rspDic["msg"] = ""

        if not company_id:
            rspDic["stat"] = "fail"
            rspDic["msg"] = u"公司不存在"
            return self.write(json.dumps(rspDic))

        try:
            dic_app = {}
            dic_app['Fapp_url'] = self.qdict.get('app_url')
            dic_app['Fapp_token'] = self.qdict.get('app_token')
            app_id = self.qdict.get('app_id')
            dic_app['Fapp_id'] = app_id.strip()
            app_secret = self.qdict.get('app_secret')
            dic_app['Fapp_secret'] = app_secret.strip()

            #check
            menuManager = MenuManager()
            access_Token = menuManager.getAccessToken(dic_app['Fapp_id'],
                                                      dic_app['Fapp_secret'])
            if access_Token.has_key('errcode'):
                rspDic["stat"] = "fail"
                rspDic["msg"] = u"验证失败"
            else:
                company_db = CompanyServices(self.db)
                company_db.update_company_by_id(int(company_id), **dic_app)
        except Exception, e:
            print e
            rspDic["stat"] = "fail"
            rspDic["msg"] = u"微信绑定失败"
示例#5
0
    def get(self, company_id, menu_code):
        if not company_id:
            return self.echo('view/login/404.html', layout='')

        error = u''
        company_db = CompanyServices(self.db)
        company = company_db.get_company_by_id(int(company_id))
        wxService = WxService(self.db)

        #获取当前menu code对应的菜单名称
        company_menu_name = ''
        if company.Fmenu_codes:
            for code in company.Fmenu_codes.split(','):
                if len(code) > 0:
                    company_menu_name = company_menu_name + ',' + wxService.query_name_by_code(
                        code)
            company_menu_name = company_menu_name.strip(',')

        #查询当前所有菜单
        menus = wxService.query_menus()

        try:
            wxService = WxService(self.db)
            error = u''

            company_db = CompanyServices(self.db)
            query = company_db.get_companys()
            query = query.filter(Company.Fid == int(company_id))
            company = query.scalar()

            menu_codes = ''
            if company.Fmenu_codes.find(menu_code) > -1:  #已绑定
                menu_codes = company.Fmenu_codes.replace(menu_code, '')
            else:
                menu_codes = company.Fmenu_codes

            #整理code顺序
            menu_codes_order = ''
            menus = wxService.query_menus()
            for menu in menus:
                if menu_codes.find(menu.code) > -1:
                    menu_codes_order = menu_codes_order + ',' + menu.code
            menu_codes = menu_codes_order.strip(',')

            #更新公众号菜单
            menuManager = MenuManager()
            dic_accessToken = menuManager.getAccessToken(
                company.Fapp_id, company.Fapp_secret)
            if len(menu_codes) == 0:  #
                menuManager.delMenu(dic_accessToken.get("access_token"))
            else:
                menus = wxService.query_menus()
                all_menu_str = wx_util.getMenuStr(menus, menu_codes,
                                                  company.Fuser_id)
                print("all_menu_str=" + all_menu_str)

                result = menuManager.refreshMenu(
                    dic_accessToken.get("access_token"), all_menu_str)
                if result <> 'ok':
                    error = u'绑定失败'
                    raise error

            #更新menu_codes
            if menu_codes <> company.Fmenu_codes:
                company_db.update_company_by_id(int(company_id),
                                                Fmenu_codes=menu_codes)

            #获取menu code对应的菜单名称
            company_menu_name = ''
            if menu_codes:
                for code in menu_codes.split(','):
                    if len(code) > 0:
                        company_menu_name = company_menu_name + ',' + wxService.query_name_by_code(
                            code)
                company_menu_name = company_menu_name.strip(',')
            else:
                company.Fmenu_codes = ''

            #查询所有菜单
            wxService = WxService(self.db)
            menus = wxService.query_menus()
            for menu in menus:
                if menu.type == 'view':
                    menu.url = setting.WX_APP_URL + menu.url
                    if menu.is_common == 0:  #url中存在参数
                        menu.url = menu.url % (company.Fuser_id)

            self.echo(
                'ops/weixin/menu.html', {
                    'error': error,
                    'company': company,
                    'company_menu_name': company_menu_name,
                    'menus': menus,
                    'page_html': '',
                })
        except Exception, e:
            e = sys.exc_info()[0](traceback.format_exc())
            print(e)

            self.echo(
                'ops/weixin/menu.html', {
                    'error': error,
                    'company': company,
                    'company_menu_name': company_menu_name,
                    'menus': menus,
                    'page_html': '',
                })