#coding=utf-8
__author__ = 'wanglu'

import requests

from util import get_access_token

def create_menu(postData,accessToken):
    url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s" % accessToken
    if isinstance(postData, unicode):
        postData = postData.encode('utf-8')
    resp = requests.post(url,data=postData)

    print resp.content

def query_menu(accessToken):
    url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s" % accessToken
    resp = requests.get(url)
    print resp.content

def delete_menu(accessToken):
    url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s" % accessToken
    resp = requests.get(url)
    print resp.content

#获取自定义菜单配置接口
def get_current_selfmenu_info(accessToken):
    url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s" % accessToken
    resp = requests.get(url)
    print resp.content


if __name__ == "__main__":
    postJson = """
    {
        "button":
        [
            {
                "type": "click",
                "name": "开发指引",
                "key":  "mpGuide"
            },
            {
                "name": "公众平台",
                "sub_button":
                [
                    {
                        "type": "view",
                        "name": "更新公告",
                        "url": "http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1418702138&token=&lang=zh_CN"
                    },
                    {
                        "type": "view",
                        "name": "接口权限说明",
                        "url": "http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1418702138&token=&lang=zh_CN"
                    },
                    {
                        "type": "view",
                        "name": "返回码说明",
                        "url": "http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234&token=&lang=zh_CN"
                    }
                ]
            },
            {
                "type": "media_id",
                "name": "旅行",
                "media_id": "z2zOokJvlzCXXNhSjF46gdx6rSghwX2xOD5GUV9nbX4"
            }
          ]
    }
    """
    accessToken = get_access_token()
    print accessToken
    create_menu(postJson,accessToken)

