3,154
社区成员




<?php
require_once "wechat.class.php";
$options = array(
'token'=>'123456', //填写你设定的key
'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey,如接口为明文模式可忽略
'appid'=>'xxxxxxx', //appid
'appsecret'=>'xxxxxxx',
'debug'=>true,
'logcallback'=>'user_dump' //日志文件
);
$weObj = new Wechat($options);
$ret = $weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败
if (!$ret) {
user_dump("验证失败");
//exit;
}
//设置菜单
$newmenu = array (
'button' => array (
0 => array (
'name' => '我是商户',
'sub_button' => array (
0 => array (
'type' => 'view',
'name' => '绑定',
'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx219d0736743e4699&redirect_uri=http://g1t5549946.imwork.net/inn_wechat_nofity/bind.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect',
),
1 => array (
'type' => 'view',
'name' => '解绑',
'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx219d0736743e4699&redirect_uri=http://g1t5549946.imwork.net/inn_wechat_nofity/unbind.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect',
),
2 => array (
'type' => 'view',
'name' => '订单查询',
'url' => 'http://g1t5549946.imwork.net/inn_wechat_nofity/order_query.php',
),
),
),
)
);
$result = $weObj->createMenu($newmenu);
$type = $weObj->getRev()->getRevType();
$events = $weObj->getRevEvent();
switch($type) {
case Wechat::MSGTYPE_TEXT:
$weObj->text("hello, I'm wechat")->reply();
exit;
break;
case Wechat::MSGTYPE_IMAGE:
break;
case Wechat::MSGTYPE_EVENT:
if($events['event'] == Wechat::EVENT_SUBSCRIBE)//首次关注
{
}
elseif ($events['event'] == Wechat::EVENT_UNSUBSCRIBE)
{
//取消关注
}
break;
default:
$weObj->text("help info")->reply();
break;
}
<?php
require_once "wechat.class.php";
class wx{
public $weObj=NULL;
public function __construct(){
$options = array(
'token'=>'123456', //填写你设定的key
'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey,如接口为明文模式可忽略
'appid'=>'xxxxxxx', //appid
'appsecret'=>'xxxxxxx',
'debug'=>true,
'logcallback'=>'user_dump' //日志文件
);
$this->weObj = new Wechat($options);
$ret = $this->weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败
if (!$ret) {
user_dump("验证失败");
//exit;
}
}
public function index(){
$type = $this->weObj->getRev()->getRevType();
$events = $this->weObj->getRevEvent();
switch($type) {
case Wechat::MSGTYPE_TEXT:
$this->weObj->text("hello, I'm wechat")->reply();
exit;
break;
case Wechat::MSGTYPE_IMAGE:
break;
case Wechat::MSGTYPE_EVENT:
if($events['event'] == Wechat::EVENT_SUBSCRIBE)//首次关注
{
}
elseif ($events['event'] == Wechat::EVENT_UNSUBSCRIBE)
{
//取消关注
}
break;
default:
$this->weObj->text("help info")->reply();
break;
}
}
//创建菜单
public function createMenu(){
$newmenu = array (
'button' => array (
0 => array (
'name' => '我是商户',
'sub_button' => array (
0 => array (
'type' => 'view',
'name' => '绑定',
'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx219d0736743e4699&redirect_uri=http://g1t5549946.imwork.net/inn_wechat_nofity/bind.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect',
),
1 => array (
'type' => 'view',
'name' => '解绑',
'url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx219d0736743e4699&redirect_uri=http://g1t5549946.imwork.net/inn_wechat_nofity/unbind.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect',
),
2 => array (
'type' => 'view',
'name' => '订单查询',
'url' => 'http://g1t5549946.imwork.net/inn_wechat_nofity/order_query.php',
),
),
),
)
);
$result = $this->weObj->createMenu($newmenu);
return $result;
}
}
$wx=new wx();
echo $wx->index(); //调用index
//echo $wx->createMenu(); //创建菜单