sinobill 2017-11-15 08:23:23 2097次浏览 0条回复 0 0 0
namespace frontend\controllers;

use Yii;
use yii\web\Controller;

class WeixinController extends Controller{
    public $token = 'test';
    private $echostr;	//是否验证Token
    public $postObj;
    private $msgType;

    //首微信接口控制器
    public function actionIndex(){
        if(isset($_GET["echostr"])){
            $this->echostr = $_GET["echostr"];
        }
        //是否第一次验证
        if(isset($this->echostr)){
            if($this->checkSignature()){
                header('content-type:text');
                echo $this->echostr;
                exit;
            }
        }else{
            $path = Yii::$app->basePath;
            echo $path;
            echo '这是微信验证页面';
            //$this->Action()
        }
    }
    //套接字处理
    private function checkSignature(){
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = $this->token;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            return true;
        }else{
            return false;
        }
    }

验证网址 http://www.yourdomain.com/index.php?r=weixin

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册