Пример #1
1
 public function weixin()
 {
     //file_put_contents('./content.txt', 'sjfsdf');
     $wechatObj = new \Weixin();
     $wechatObj->responseMsg();
     //$wechatObj->valid();
 }
Пример #2
0
 /**
  * default action 'index'
  *
  * @param Request $request
  * @param Response $response
  */
 public function index(Request $request, Response $response)
 {
     $t = $request->arg(1);
     $wx = new Weixin([], $t);
     if (!isset($_GET['echostr'])) {
         if ($wx->checkSignature()) {
             //签名检测
             $wx->responseMsg();
         } else {
             echo '';
         }
     } else {
         //接口验证
         $wx->valid();
     }
     exit;
 }
 public function __construct()
 {
     //判断hash是否存在
     if (empty($_GET["hash"])) {
         echo '#10000非法请求';
         die;
     }
     G('begin');
     $info = S('Accountinfo');
     if (empty($info)) {
         $info = M("Account")->where(array('account_oldid' => $_GET["hash"]))->find();
         $info['Weixin_trace'] = false;
         S('Accountinfo', $info);
     }
     $info['Weixin_trace'] = false;
     //判断hash是否存在
     if (empty($info)) {
         echo '#10001账号不存在';
         die;
     } else {
         $this->Account_info = $info;
     }
     global $_G;
     $_G = $info;
     $token = $info['account_token'];
     import('Weixin.ORG.Weixin');
     $wechatObj = new \Weixin($_GET["echostr"], $token, $GLOBALS["HTTP_RAW_POST_DATA"], $_GET["signature"], $_GET["timestamp"], $_GET["nonce"]);
     $wechatinfo = $wechatObj->responseMsg();
     if (is_array($wechatinfo) && !empty($token)) {
         session('token', $token);
         session('from', $wechatinfo['fromusername']);
         session('openid', $wechatinfo['fromusername']);
         session('to', $wechatinfo['tousername']);
         //过滤器行为
         hook('weixin_begin_filter', &$wechatinfo);
         global $_W;
         $_W = $wechatinfo;
         //预处理行为
         hook('weixin_begin');
     } else {
         echo '这里是微信请求的接口地址,请将本地址填写的微信的TOKEN请求地址';
         die;
     }
 }