对接微信公众平台一些问题

1.自定义菜单创建的问题
在使用微信公众平台的时候遇见的一些问题
创建菜单,微信公众平台只能创建三个菜单必须在同一个button下面
子菜单则可以创建多个最多5个

$data["button"] = array(
            array(
                "type" => "click",
                "name" => "菜单A",
                "key" => "caidan"
            ),
            array(
                "name" => "菜单B",
                "sub_button" => array(
                    array(
                        "type" => "view",
                        "name" => "搜索",
                        "url" => "http://www.baidu.com"
                    ),

                ),
            ),
            array(
                "type" => "click",
                "name" => "用户信息",
                "key" => "userdata",
            ),
        );
  1. 发送至微信服务时 应该使用json 发送
$postData = json_encode($data, JSON_UNESCAPED_UNICODE);
  1. 获取openid的时候需要通过开放平台获取,互动消息需要使用服务器,但是可直接发送模板消息

  2. php curl get代码

public function get($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        $data = curl_exec($curl);
        return $data;
    }
  1. php curl post代码
public function post($url, $filedata)
    {
        $curl = curl_init();
        if (class_exists('./CURLFile')) {
            curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
        }

        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        if (!empty($filedata)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $filedata);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
// 接受消息
$json = file_get_contents("php://input");
$json = json_decode($json, true);
print_r($json);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容