<?php

header("content-type:text/html;charset=utf-8");
// echo "klkdlkl";die;
require_once '../common/php/dbaccess.php';
require_once '../common/php/configSelf.php';
require_once 'sdk_sunpeijun.php';
require_once '../common/php/config.php';
traceHttp();
define("TOKEN", "weixin");
//微信端验证token
define('IP', "www.chinwhiz.cn");
$db = new DB();
$wechatObj = new wechatCallbackapiTest();
$access_token = $wechatObj->getAccessToken($appIdSelf, $appSecretSelf);
$wx = new wechat($appIdSelf, $appSecretSelf, $access_token);
if (isset($_GET['echostr'])) {
    $wechatObj->valid();
} else {
    //$wx->sendMsgToAll();
    $wechatObj->responseMsg();
    //  	$wechatObj->createMenu();
}
class wechatCallbackapiTest
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if ($this->checkSignature()) {
            ob_clean();
            echo $echoStr;
Example #2
0
 public function index()
 {
     //define('APP_DEBUG', false);
     //define('ENGINE_NAME','sae');
     traceHttp();
     $token = 'token';
     //微信后台填写的TOKEN
     //调试
     if (isset($_GET['echostr'])) {
         $this->valid();
     } else {
         //$this->responseMsg();
         vendor('Weixinpay.WxPayJsApiPay');
         $appid = \WxPayConfig::APPID;
         $crypt = \WxPayConfig::APPSECRET;
         /* 加载微信SDK */
         $wechat = new Wechat($token, $appid, $crypt);
         /* 获取请求信息 */
         $data = $wechat->request();
         if ($data && is_array($data)) {
             /**
              * 你可以在这里分析数据,决定要返回给用户什么样的信息
              * 接受到的信息类型有10种,分别使用下面10个常量标识
              * Wechat::MSG_TYPE_TEXT       //文本消息
              * Wechat::MSG_TYPE_IMAGE      //图片消息
              * Wechat::MSG_TYPE_VOICE      //音频消息
              * Wechat::MSG_TYPE_VIDEO      //视频消息
              * Wechat::MSG_TYPE_SHORTVIDEO //视频消息
              * Wechat::MSG_TYPE_MUSIC      //音乐消息
              * Wechat::MSG_TYPE_NEWS       //图文消息(推送过来的应该不存在这种类型,但是可以给用户回复该类型消息)
              * Wechat::MSG_TYPE_LOCATION   //位置消息
              * Wechat::MSG_TYPE_LINK       //连接消息
              * Wechat::MSG_TYPE_EVENT      //事件消息
              *
              * 事件消息又分为下面五种
              * Wechat::MSG_EVENT_SUBSCRIBE    //订阅
              * Wechat::MSG_EVENT_UNSUBSCRIBE  //取消订阅
              * Wechat::MSG_EVENT_SCAN         //二维码扫描
              * Wechat::MSG_EVENT_LOCATION     //报告位置
              * Wechat::MSG_EVENT_CLICK        //菜单点击
              */
             //记录微信推送过来的数据
             file_put_contents('./data.json', json_encode($data));
             /* 响应当前请求(自动回复) */
             //$wechat->response($content, $type);
             /**
              * 响应当前请求还有以下方法可以使用
              * 具体参数格式说明请参考文档
              * 
              * $wechat->replyText($text); //回复文本消息
              * $wechat->replyImage($media_id); //回复图片消息
              * $wechat->replyVoice($media_id); //回复音频消息
              * $wechat->replyVideo($media_id, $title, $discription); //回复视频消息
              * $wechat->replyMusic($title, $discription, $musicurl, $hqmusicurl, $thumb_media_id); //回复音乐消息
              * $wechat->replyNews($news, $news1, $news2, $news3); //回复多条图文消息
              * $wechat->replyNewsOnce($title, $discription, $url, $picurl); //回复单条图文消息
              * 
              */
             //执行Demo
             $this->demo($wechat, $data);
         }
     }
 }