新普金娱乐网址


Html5 Geolocation获取地理地方音讯

汉堡假期

地理微信菜单创制

  • 十二月 18, 2018
  • 地理
  • 没有评论

即由定义菜单接口可实现以下几栽类型按钮,如下:
  1、click:点击推事件
  用户点击click类型按钮后,微信服务器会透过音信接口推送音信类型为event
的社团于开发者(参考音信接口指南),并且带来及按钮中开发者填写的key值,开发者能够经过自定义之key值与用户展开交互;
  2、view:跳转URL
  用户点击view类型按钮后,微信客户端将碰面打开开发者在按钮中填入的网页URL,可及网页授权获取用户基本音讯接口结合,得到用户大旨音信。
  3、scancode_push:扫码推事件
  用户点击按钮后,微信客户端将调动起扫一扫工具,完成扫码操作后展现扫描结果(如要是URL,将上URL),且会将扫码的结果传被开发者,开发者可以下信息。
  4、scancode_waitmsg:扫码推事件且弹来“新闻接收中”指示框
  用户点击按钮后,微信客户端将调整起扫一扫工具,完成扫码操作后,将扫码的结果传被开发者,同时竣工于扫一扫工具,然后弹出“新闻接收中”提示框,随后可能会师收开发者下发的信息。
  5、pic_sysphoto:弹有序列视频发图
  用户点击按钮后,微信客户端将调整起系统相机,完成拍摄操作后,会拿拍之像发送给开发者,并推送事件为开发者,同时终止于系统相机,随后可能相会接受开发者下发的信息。
  6、pic_photo_or_album:弹出拍照或者相册发图
  用户点击按钮后,微信客户端将弹出采纳器供用户接纳“拍照”或者“从手机相册采纳”。用户挑选后虽然运动其它二种植流程。
  7、pic_weixin:弹出微信相册发图器
  用户点击按钮后,微信客户端将调整起微信相册,完成采纳操作后,将择的肖像发送给开发者的服务器,并推送事件给开发者,同时终止于相册,随后可能会合接收开发者下发的音信。
  8、location_select:弹出地理地方采取器
  用户点击按钮后,微信客户端将调起地理地点选工具,完成选用操作后,将甄选的地理地方发送给开发者的服务器,同时终止于地方选工具,随后可能晤面接收开发者下发的音。

用户点击菜单之后,微信会将事件推送给接口程序,相应的接口参数与表明

1.开立菜单

地理 1

  创立菜单的接口如下所示:
         
  https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

用户点击自定义菜单后,接口程序收到的XML数据包如下所示:

   成立菜单时,需要用菜单内容协会成为如下结构,以POST的不二法门于微信服务器交由。

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuN_DFnKZwBaUKQ1RJD2Tr9M]]></FromUserName>
    <CreateTime>1468050882</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[CLICK]]></Event>
    <EventKey><![CDATA[TEXT]]></EventKey>
</xml>
{
    "button": [
        {
            "name": "扫码", 
            "sub_button": [
                {
                    "type": "scancode_waitmsg", 
                    "name": "扫码带提示", 
                    "key": "rselfmenu_0_0"
                }, 
                {
                    "type": "scancode_push", 
                    "name": "扫码推事件", 
                    "key": "rselfmenu_0_1"
                }
            ]
        }, 
        {
            "name": "发图", 
            "sub_button": [
                {
                    "type": "pic_sysphoto", 
                    "name": "系统拍照发图", 
                    "key": "rselfmenu_1_0"
                }, 
                {
                    "type": "pic_photo_or_album", 
                    "name": "拍照或者相册发图", 
                    "key": "rselfmenu_1_1"
                }, 
                {
                    "type": "pic_weixin", 
                    "name": "微信相册发图", 
                    "key": "rselfmenu_1_2"
                }
            ]
        }, 
        {
            "name": "其他", 
            "sub_button": [
                {
                    "name": "发送位置", 
                    "type": "location_select", 
                    "key": "rselfmenu_2_0"
                }, 
                {
                    "type": "click", 
                    "name": "今日歌曲", 
                    "key": "V1001_TODAY_MUSIC"
                }, 
                {
                    "type": "view", 
                    "name": "搜索", 
                    "url": "http://www.soso.com/"
                }
            ]
        }
    ]
}

按钮类型为view的菜谱点击后,上报的XML如下所示:

从定义菜单内容的参数表明要表5-3所体现:
地理 2

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuN_DFnKZwBaUKQ1RJD2Tr9M]]></FromUserName>
    <CreateTime>1468050934</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[VIEW]]></Event>
    <EventKey><![CDATA[http://xw.qq.com/]]></EventKey>
    <MenuId>410418124</MenuId>
</xml>

吃微信公众账号创设于定义菜单的代码实现如下所示:

点击scancode_push类型的菜单时,接口程序收到的XML数据包如下所示。
  微信会直接运行解码后底情节,比如间接入关注界面。

 

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuN_DFnKZwBaUKQ1RJD2Tr9M]]></FromUserName>
    <CreateTime>1468051082</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[scancode_push]]></Event>
    <EventKey><![CDATA[rselfmenu_2_2]]></EventKey>
    <ScanCodeInfo>
        <ScanType><![CDATA[qrcode]]></ScanType>
        <ScanResult><![CDATA[http://weixin.qq.com/r/l0Ozq9-EbYISrZvI9xaF]]></ScanResult>
    </ScanCodeInfo>
</xml>
$jsonmenu = '{
    "button": [
        {
            "name": "扫码", 
            "sub_button": [
                {
                    "type": "scancode_waitmsg", 
                    "name": "扫码带提示", 
                    "key": "rselfmenu_0_0"
                }, 
                {
                    "type": "scancode_push", 
                    "name": "扫码推事件", 
                    "key": "rselfmenu_0_1"
                }
            ]
        }, 
        {
            "name": "发图", 
            "sub_button": [
                {
                    "type": "pic_sysphoto", 
                    "name": "系统拍照发图", 
                    "key": "rselfmenu_1_0"
                }, 
                {
                    "type": "pic_photo_or_album", 
                    "name": "拍照或者相册发图", 
                    "key": "rselfmenu_1_1"
                }, 
                {
                    "type": "pic_weixin", 
                    "name": "微信相册发图", 
                    "key": "rselfmenu_1_2"
                }
            ]
        }, 
        {
            "name": "其他", 
            "sub_button": [
                {
                    "name": "发送位置", 
                    "type": "location_select", 
                    "key": "rselfmenu_2_0"
                }, 
                {
                    "type": "click", 
                    "name": "今日歌曲", 
                    "key": "V1001_TODAY_MUSIC"
                }, 
                {
                    "type": "view", 
                    "name": "搜索", 
                    "url": "http://www.soso.com/"
                }
            ]
        }
    ]
}
';

$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
var_dump($result);

function https_request($url,$data = null)
{
$curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
    curl_close($curl);
return $output;
}

点击scancode_waitmsg类型的食谱时,接口程序收到的XML数据包如下所示:

 

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuN_DFnKZwBaUKQ1RJD2Tr9M]]></FromUserName>
    <CreateTime>1468051112</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[scancode_waitmsg]]></Event>
    <EventKey><![CDATA[rselfmenu_2_1]]></EventKey>
    <ScanCodeInfo>
        <ScanType><![CDATA[qrcode]]></ScanType>
        <ScanResult><![CDATA[http://weixin.qq.com/r/l0Ozq9-EbYISrZvI9xaF]]></ScanResult>
    </ScanCodeInfo>
</xml>

是的时之回来JSON数据包如下:
{"errcode":0,"errmsg":"ok"}

点击pic_sysphoto类型的菜单后,调用手机里的相机效用,而拍后再也发作过来时,就接受一个图形信息。点击菜单时的XML数据如下所示:

荒唐时的回到JSON数据包如下(示例为无效菜单名长度):
{"errcode":40018,"errmsg":"invalid button name size"}

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuNH_V1zk4x3zTN1IMoAZDW0]]></FromUserName>
    <CreateTime>1468051307</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[pic_sysphoto]]></Event>
    <EventKey><![CDATA[rselfmenu_2_3]]></EventKey>
    <SendPicsInfo>
        <Count>1</Count>
        <PicList>
            <item>
                <PicMd5Sum><![CDATA[4cc7f5ab2c499b01655e99a868ef3519]]></PicMd5Sum>
            </item>
        </PicList>
    </SendPicsInfo>
</xml>

errcode也大局重临码。

点击pic_photo_or_album类型的菜单之后,先推动送菜单事件推送给开发者,然后重新推送图片消息,点击菜单时的XML数据如下所示:

 

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuNH_V1zk4x3zTN1IMoAZDW0]]></FromUserName>
    <CreateTime>1468051528</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[pic_photo_or_album]]></Event>
    <EventKey><![CDATA[rselfmenu_2_4]]></EventKey>
    <SendPicsInfo>
        <Count>2</Count>
        <PicList>
            <item>
                <PicMd5Sum><![CDATA[b5c23feac0987db7ddda1b0a3addba9d]]></PicMd5Sum>
            </item>
            <item>
                <PicMd5Sum><![CDATA[59c3eb7e2124a75986295b8842573951]]></PicMd5Sum>
            </item>
        </PicList>
    </SendPicsInfo>
</xml>

点击pic_weixin类型的菜系时,微信客户端将调动起系统相机,用户可以采用就发出影或者拓展录像,微信会将像发送给开发者,下边是均等涂鸦接纳3摆设像时之XML数据:

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuNH_V1zk4x3zTN1IMoAZDW0]]></FromUserName>
    <CreateTime>1468051592</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[pic_weixin]]></Event>
    <EventKey><![CDATA[rselfmenu_2_5]]></EventKey>
    <SendPicsInfo>
        <Count>3</Count>
        <PicList>
            <item>
                <PicMd5Sum><![CDATA[59c3eb7e2124a75986295b8842573951]]></PicMd5Sum>
            </item>
            <item>
                <PicMd5Sum><![CDATA[b5c23feac0987db7ddda1b0a3addba9d]]></PicMd5Sum>
            </item>
            <item>
                <PicMd5Sum><![CDATA[4cc7f5ab2c499b01655e99a868ef3519]]></PicMd5Sum>
            </item>
        </PicList>
    </SendPicsInfo>
</xml>

点击location_select类型的菜谱之后,将会见调起发送地点功效,在用户发送地点后,会重复推送一个地理地点音讯效率为用户,
XML数据如下所示。

<xml>
    <ToUserName><![CDATA[gh_36dd0f0b3132]]></ToUserName>
    <FromUserName><![CDATA[oQW8FuNH_V1zk4x3zTN1IMoAZDW0]]></FromUserName>
    <CreateTime>1468051658</CreateTime>
    <MsgType><![CDATA[event]]></MsgType>
    <Event><![CDATA[location_select]]></Event>
    <EventKey><![CDATA[SIGNIN]]></EventKey>
    <SendLocationInfo>
        <Location_X><![CDATA[22.53996467590332]]></Location_X>
        <Location_Y><![CDATA[113.93487548828125]]></Location_Y>
        <Scale><![CDATA[17]]></Scale>
        <Label><![CDATA[广东省深圳市南山区深南大道10000号]]></Label>
        <Poiname><![CDATA[腾讯大厦]]></Poiname>
    </SendLocationInfo>
</xml>

音信接口中,响应自定义菜单点击事件之为主代码如下所示:

//接收事件消息
private function receiveEvent($object)
{
    $content = "";
    switch ($object->Event)
    {
        case "subscribe":
            $content = "欢迎关注方倍工作室 ";
            $content .= (!empty($object->EventKey))?("\n来自二维码场景 ".str_replace("qrscene_","",$object->EventKey)):"";
            break;
        case "unsubscribe":
            $content = "取消关注";
            break;
        case "CLICK":
            switch ($object->EventKey)
            {
                case "COMPANY":
                    $content = array();
                    $content[] = array("Title"=>"方倍工作室", "Description"=>"", "PicUrl"=>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"http://m.cnblogs.com/?u=txw1958");
                    break;
                default:
                    $content = "点击菜单:".$object->EventKey;
                    break;
            }
            break;
        case "VIEW":
            $content = "跳转链接 ".$object->EventKey;
            break;
        case "SCAN":
            $content = "扫描场景 ".$object->EventKey;
            break;
        case "LOCATION":
            $content = "上传位置:纬度 ".$object->Latitude.";经度 ".$object->Longitude;
            break;
        case "scancode_waitmsg":
            $content = "扫码带提示:类型 ".$object->ScanCodeInfo->ScanType." 结果:".$object->ScanCodeInfo->ScanResult;
            break;
        case "scancode_push":
            $content = "扫码推事件";
            break;
        case "pic_sysphoto":
            $content = "系统拍照";
            break;
        case "pic_weixin":
            $content = "相册发图:数量 ".$object->SendPicsInfo->Count;
            break;
        case "pic_photo_or_album":
            $content = "拍照或者相册:数量 ".$object->SendPicsInfo->Count;
            break;
        case "location_select":
            $content = "发送位置:标签 ".$object->SendLocationInfo->Label;
            break;
        default:
            $content = "receive a new event: ".$object->Event." \n技术支持 方倍工作室";
            break;
    }

    if(is_array($content)){
        if (isset($content[0]['PicUrl'])){
            $result = $this->transmitNews($object, $content);
        }else if (isset($content['MusicUrl'])){
            $result = $this->transmitMusic($object, $content);
        }
    }else{
        $result = $this->transmitText($object, $content);
    }
    return $result;
}

 

相关文章

No Comments, Be The First!
近期评论
    分类目录
    功能
    网站地图xml地图