Esempio n. 1
0
 public function index()
 {
     import("@.ORG.Weixin");
     $config = $this->Config;
     $wxconfig = F("wxconfig");
     $user = M("user");
     $data = array();
     $wechatObj = new Wechat();
     if ($wxconfig["wstatu"] != "") {
         $data = $wechatObj->responseMsg($idx);
         //接收到的
         $me = $data['me'];
         $guest = $data['user'];
         //////////////////////*用户打入库-开始*///////////////
         $this->adduser($guest);
         if ($data['key'] == "ewm") {
             $ewm = $wechatObj->ewm(2, 1);
             $wechatObj->sendtext($guest, $me, $ewm);
         }
         $wechatObj->sendtext($guest, $me, $guest);
         exit;
         ///////////////////////////////事件开始/////////////////////////
         if ($data['type'] == "event") {
             //关注
             if ($data['event'] == "subscribe" || $data['event'] == "SCAN") {
                 if ($data['key'] == 1) {
                     $user = M("user")->where("wxid='" . sysmd5($guest) . "'")->setfield('vip', 1);
                     $map1['url'] = "http://mall.bydauto.com.cn/echo/index/store";
                     $map1['title'] = "vip会议标题['待定..']";
                     $map1['description'] = "描述的文字['待定..'],点击进去的链接待定,下面的图片大小700x400";
                     $map1['thumb'] = "http://byd.gzqizhen.com/Public/byd/byd.jpg";
                     $wechatObj->sendimg($guest, $me, $map1);
                     exit;
                 }
                 if ($data['key'] == 2) {
                     $vip = M("user")->where("wxid='" . sysmd5($guest) . "'")->getfield('vip');
                     if (!$vip) {
                         $user = M("user")->where("wxid='" . sysmd5($guest) . "'")->setfield('vip', 2);
                     }
                     $map2['url'] = "http://mall.bydauto.com.cn/echo/index/store";
                     $map2['title'] = "新能源['待定..']";
                     $map2['description'] = "描述的文字['待定..']下面的图片大小700x400";
                     $map2['thumb'] = "http://byd.gzqizhen.com/Public/byd/byd.jpg";
                     $wechatObj->sendimg($guest, $me, $map2);
                     // $wechatObj->sendtext($guest,$me,"新能源");
                     exit;
                 }
             }
         }
         ///////////////////////////////事件结束/////////////////////////
         $wechatObj->sendimg($guest, $me, $wxconfig);
     } else {
         M("config")->where("varname='wstatu'")->setField('value', "清理此位置可以重新设置微信接入!");
         $wechatObj->valid($wxconfig["token"]);
         savecache("Config");
     }
 }
Esempio n. 2
0
 public function index()
 {
     import("@.ORG.Weixin");
     $config = $this->Config;
     $wxconfig = F("wxconfig");
     $user = M("user");
     $data = array();
     $wechatObj = new Wechat();
     if ($wxconfig["wstatu"] != "") {
         $data = $wechatObj->responseMsg($idx);
         //接收到的
         $me = $data['me'];
         $guest = $data['user'];
         //////////////////////*用户打入库-开始*///////////////
         $this->adduser($guest);
         ///////////////////////////////事件结束/////////////////////////
         $wechatObj->sendimg($guest, $me, $wxconfig);
     } else {
         M("config")->where("varname='wstatu'")->setField('value', "清理此位置可以重新设置微信接入!");
         $wechatObj->valid($wxconfig["token"]);
         savecache("Config");
     }
 }
Esempio n. 3
0
<?php

//声明一个常量定义一个token值, token
define("TOKEN", "199036");
//通过Wechat类, 创建一个对象
$wechatObj = new Wechat();
//如果没有通过GET收到echostr字符串, 说明不是再使用token验证
if (!isset($_GET['echostr'])) {
    //调用wecat对象中的方法响应用户消息
    $wechatObj->responseMsg();
} else {
    //调用valid()方法,进行token验证
    $wechatObj->valid();
}
//声明一个Wechat的类, 处理接收消息, 接收事件, 响应各种消息, 以及token验证
class Wechat
{
    //验证签名, 手册中原代码改写
    public function valid()
    {
        //在开发者首次提交验证申请时,微信服务器将发送GET请求到填写的URL上,并且带上四个参数(signature、timestamp、nonce、echostr),开发者通过对签名(即signature)的效验,来判断此条消息的真实性。
        $echoStr = $_GET["echostr"];
        // 随机字符串
        $signature = $_GET["signature"];
        //微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
        $timestamp = $_GET["timestamp"];
        //时间戳
        $nonce = $_GET["nonce"];
        // 随机数
        //上面通过常量声明的token值
        $token = TOKEN;