Ejemplo n.º 1
0
    def create_qrcode(self, scene_id, permanent=False, expire_seconds=1800):
        '''创建带参数二维码,永久的要permanent=True'''
        scene_id = str(scene_id)
        url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s' % self.get_token()
        if permanent:
            post_data = {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": scene_id}}}
            dirpath = '/var/data/yimi-img/upload/qrcode/'+self.appid+'/permanent/'
            expire_seconds = 0
        else:
            post_data = {"expire_seconds": expire_seconds, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": scene_id}}}
            dirpath = '/var/data/yimi-img/upload/qrcode/'+self.appid+'/tmp/'

        return_data = method_post_api(url, post_data)
        if return_data.get('ticket'):
            qrcode = self.qrcodes.filter(scene_id=scene_id).first()
            url = dirpath+scene_id+'.jpg'
            url = url.replace('/var/data/yimi-img/upload/', 'http://%s/media/' % self.domain)
            if not qrcode:
                qrcode = self.qrcodes.create(scene_id=scene_id, url=url, expire_seconds=expire_seconds)
            else:
                qrcode.url=url
                qrcode.expire_seconds=expire_seconds
                qrcode.save()
            filedata = urllib2.urlopen('https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='+return_data.get('ticket')).read()
            if not os.path.exists(dirpath):
                os.makedirs(dirpath)
            file(dirpath+scene_id+'.jpg', 'wb').write(filedata)
Ejemplo n.º 2
0
    def create_qrcode(self, scene_id, permanent=False, expire_seconds=1800):
        '''创建带参数二维码,永久的要permanent=True'''
        scene_id = str(scene_id)
        url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s' % self.get_token()
        if permanent:
            post_data = {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": scene_id}}}
            dirpath = '/var/data/yimi-img/upload/qrcode/'+self.appid+'/permanent/'
            expire_seconds = 0
        else:
            post_data = {"expire_seconds": expire_seconds, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": scene_id}}}
            dirpath = '/var/data/yimi-img/upload/qrcode/'+self.appid+'/tmp/'

        return_data = method_post_api(url, post_data)
        if return_data.get('ticket'):
            qrcode = self.qrcodes.filter(scene_id=scene_id).first()
            url = dirpath+scene_id+'.jpg'
            url = url.replace('/var/data/yimi-img/upload/', 'http://%s/media/' % self.domain)
            if not qrcode:
                qrcode = self.qrcodes.create(scene_id=scene_id, url=url, expire_seconds=expire_seconds)
            else:
                qrcode.url=url
                qrcode.expire_seconds=expire_seconds
                qrcode.save()
            filedata = urllib2.urlopen('https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='+return_data.get('ticket')).read()
            if not os.path.exists(dirpath):
                os.makedirs(dirpath)
            file(dirpath+scene_id+'.jpg', 'wb').write(filedata)
Ejemplo n.º 3
0
 def create_menu(self, post_data):
     '''创建菜单,成功返回True'''
     url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' + self.get_token(
     )
     return_data = method_post_api(url, post_data)
     print return_data
     return self.successed(return_data)
Ejemplo n.º 4
0
 def groups_members_batchupdate(self, openid_list, to_groupid):
     '''批量移动用户分组'''
     post_data = {
         'openid_list':openid_list,
         'to_groupid':to_groupid,
     }
     return_data = method_post_api(url, post_data)
     return return_data.get('errcode')
Ejemplo n.º 5
0
 def del_material(self, media_id):
     '''删除永久素材'''
     post_data = {
         'media_id':media_id,
     }
     url = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=%s" % self.get_token()
     return_data = method_post_api(url, post_data)
     return return_data.get('errcode')
Ejemplo n.º 6
0
 def get_batchget_user_info(self, openid_list):
     post_data = {}
     user_list = []
     for openid in openid_list:
         user_list.append({'openid':openid, 'lang':'zh-CN'})
     post_data['user_list'] = user_list
     url = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=%s'%(self.get_token())
     return_data = method_post_api(url, post_data)
     return return_data.get('user_info_list')
Ejemplo n.º 7
0
 def search_user_group(self, appuser):
     post_data = {"openid":appuser.openid}
     url = 'https://api.weixin.qq.com/cgi-bin/groups/getid?access_token='+ self.get_token()
     return_data = method_post_api(url, post_data)
     group_id = return_data.get('groupid')
     if group_id:
         return group_id
     else:
         return ''
Ejemplo n.º 8
0
 def get_material_add_material_api(self, media, type):
     '''新增其他类型素材'''
     post_data = {
         'media':media,
         'type':type,
     }
     url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%s" % self.get_token()
     return_data = method_post_api(url, post_data)
     return return_data
Ejemplo n.º 9
0
 def get_batchget_material(self, type, offset=0, count=20):
     '''获取素材列表'''
     post_data = {
         'type':type,
         'offset':offset,
         'count':count,
     }
     url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=%s" %self.get_token()
     return_data = method_post_api(url, post_data)
     return return_data
Ejemplo n.º 10
0
    def create_qrcode(self, scene_id, permanent=False, expire_seconds=1800):
        '''创建带参数二维码,永久的要permanent=True'''
        scene_id = str(scene_id)
        url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s' % self.get_token()
        if permanent:
            post_data = {"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": scene_id}}}
            expire_seconds = 0
        else:
            post_data = {
                "expire_seconds": expire_seconds, 
                "action_name": "QR_SCENE", 
                "action_info": {"scene": {"scene_id": scene_id}},
            }

        return_data = method_post_api(url, post_data)
        if return_data.get('ticket'):
            return 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='+return_data.get('ticket')
Ejemplo n.º 11
0
 def set_beizhu(self, appitem , post_data):
     '''设置备注名字'''
     url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=' + appitem.get_token()
     return_data = method_post_api(url, post_data)
     return self.successed(return_data)   
Ejemplo n.º 12
0
 def send_template_msg(self, post_data):
     '''发送模板消息'''
     url_api = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s' % self.get_token()
     return_data = method_post_api(url_api, post_data)
     return self.successed(return_data)
Ejemplo n.º 13
0
 def post_rename_user(self, post_data):
     '''移动分组'''
     url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=' + self.get_token()
     return_data = method_post_api(url, post_data)
     return self.successed(return_data)        
Ejemplo n.º 14
0
 def post_kfaccount_update(self, post_data):
     url = 'https://api.weixin.qq.com/customservice/kfaccount/update?access_token=%s&kf_account=%s' % (self.token,kf_account) 
     dict_data = method_post_api(url, post_data)
     return self.successed(dict_data)   
Ejemplo n.º 15
0
 def post_group(self, post_data):
     '''创建分组'''
     url = 'https://api.weixin.qq.com/cgi-bin/groups/create?access_token=' + self.get_token()
     return_data = method_post_api(url, post_data)
     return self.group_successed(return_data)        
Ejemplo n.º 16
0
 def post_process(self, post_data):
     '''发送客服数据过程'''
     url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' + self.get_token()
     return_data = method_post_api(url, post_data)
     return self.successed(return_data)        
Ejemplo n.º 17
0
 def create_menu(self, post_data):
     '''创建菜单,成功返回True'''
     url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='+self.get_token()
     return_data = method_post_api(url, post_data)
     print return_data
     return self.successed(return_data)
Ejemplo n.º 18
0
 def post_user_group(self, post_data):
     '''移动分组'''
     url = 'https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=' + self.get_token()
     return_data = method_post_api(url, post_data)
     return self.successed(return_data)        
Ejemplo n.º 19
0
 def post_group_msg(self, post_data):
     '''发送分组消息'''
     url = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=' + self.get_token()
     return_data = method_post_api(url, post_data)
     return self.group_fasong_successed(return_data)        
Ejemplo n.º 20
0
 def post_kfaccount(self, post_data):
     '''创建分组'''
     url = 'https://api.weixin.qq.com/customservice/kfaccount/add?access_token=' + self.get_token()
     return_data = method_post_api(url, post_data)
     return self.successed(return_data)