public function actionIndex(){ $nonce = Yii::$app->request->get('nonce'); $token = 'adshare'; $timestamp = Yii::$app->request->get('timestamp'); $echostr = Yii::$app->request->get('echostr'); $signature = Yii::$app->request->get('signature'); $array = array(); $array = array($nonce,$timestamp,$token); sort($array); $str = sha1(implode($array)); /*if($str == $signature){ echo $echostr; }*/ if($str == $signature && $echostr){ return $echostr; }else{ self::actionMessage(); } }
注意方法中被注釋的代碼,不管是初次還是再次修改,都需要把$echostr返回給微信,才能正確驗證,否則會一直提示token的問題!