def send_subscribe_msg(touser=None, template_id=None, data=None, page=None, miniprogram_state=None, lang=None): """ 发送订阅消息 wx_doc: https://developers.weixin.qq.com/miniprogram/dev/api-backend/ open-api/subscribe-message/subscribeMessage.send.html :param touser: 接收者(用户)的 openid :param template_id: 所需下发的订阅模板id :param data: 模板内容 :param page: 点击模板卡片后的跳转页面 :param miniprogram_state: 跳转小程序类型 :param lang: 进入小程序查看”的语言类型 :return: """ if touser is None or template_id is None or data is None: # 这3个参数必填 raise ValueError() rq_data = dict(touser=touser, template_id=template_id, data=data, page=page, miniprogram_state=miniprogram_state, lang=lang) rq_data = dict_rm_none(rq_data) base_url = current_app.config['SEND_SUBSCRIBE_MSG_BASE_URL'] url = base_url + "?access_token=" + get_access_token() requests.post(url, data=json.dumps(rq_data))
def create_banner(cls, data): """创建一个轮播图""" data = dict_rm_none(data) with db.auto_commit(): banner = Banner() banner.set_attrs(data) db.session.add(banner) return True
def get_a_unlimit_code(data): """ 取一张无限制的微信小程序二维码 :param data: :return: 图片的 url """ base_url = current_app.config['GET_WX_A_UNLIMIT_CODE_BASE_URL'] access_token = get_access_token() url = base_url + "?access_token=" + access_token data = dict_rm_none(data) # 剔除值为 None 的数据 try: wx_data = requests.post(url, data=json.dumps(data)) filename = save_code(wx_data.content) img_url = current_app.config['DOMAIN'] + url_for( 'static', filename='api/wx/unlimit_code/' + filename) return img_url except Exception: ServerError()
def update_ad(cls, aid, data): ad = cls.query.filter_by(id=aid, delete_time=None).first_or_404() data = dict_rm_none(data) with db.auto_commit(): ad.set_attrs(data) return True
def update_banner(cls, bid, data): banner = cls.query.filter_by(id=bid, delete_time=None).first_or_404() data = dict_rm_none(data) with db.auto_commit(): banner.set_attrs(data) return True