Openresty实现微信公众号的自定义菜单

    老规矩先添加一个location:

    location /menu_create {
            content_by_lua_file /path/to/menu_create.lua;
    }

    然后就是干货:

local http = require "resty.http"
local cjson = require "cjson"
local hc = http:new()
-- menu setting
local button1 = {}
local button2 = {}
-- button1

button1["name"] = "主按钮1"
button1["sub_button"] = {}
button1["sub_button"][1] = {}
button1["sub_button"][1]["type"] = "view"
button1["sub_button"][1]["name"] = "子按钮1"
button1["sub_button"][1]["url"] = "http://www.baidu.com"
button1["sub_button"][2] = {}
button1["sub_button"][2]["type"] = "view"
button1["sub_button"][2]["name"] = "子按钮2"
button1["sub_button"][2]["url"] = 
-- button2
button2["type"] = "view"
button2["name"] = "主按钮2"
button2["url"] = "http://www.baidu.com"

local menu = {}
menu["button"] = {button1, button2}
local menu_json = cjson.encode(menu)
ngx.say(menu_json)
local res, err = hc:request_uri ("https://api.weixin.qq.com/cgi-bin/menu/create", {
        method = "POST",
        query = {
            access_token = "ACCESS_TOKEN",
        },
        ssl_verify = false,
        body = menu_json,
        })
if not res then
        ngx.say("failed to request: ", err)
        return
end
ngx.say(res.body)


    主要是演示一下如何利用lua_resty_http实现https的POST功能。

转载于:https://my.oschina.net/chrisforbt/blog/639568

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值