123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace api\controllers;
- use Yii;
- use yii\base\InvalidParamException;
- use yii\web\BadRequestHttpException;
- use yii\web\Controller;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use common\models\LoginForm;
- use frontend\models\PasswordResetRequestForm;
- use frontend\models\ResetPasswordForm;
- use frontend\models\SignupForm;
- use frontend\models\ContactForm;
- /**
- * Site controller
- */
- class SiteController extends Controller
- {
- /**
- * @inheritdoc
- /**
- * Displays homepage.
- *
- * @return mixed
- */
- public function actionIndex()
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- return [
- 'message' => 'API test Ok!',
- 'code' => 100,
- ];
- // return $this->render('index');
- }
- /**
- * Displays homepage.
- *
- * @return mixed
- */
- public function actionPage()
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $params=Yii::$app->request->get();
- unset($params['r']);
- // var_dump($params);die;
- // die;
- $signature = $params["signature"];//本地签名
- $timestamp = $params["timestamp"];//时间戳
- // $params = $_GET["params"];
- //valid signature , option
- if($this->checkSignature($params,$timestamp,$signature)){
- return [
- 'message' => 'signature test Ok!',
- 'code' => 100,
- ];
- }else{
- return [
- 'message' => 'signature test fail!',
- 'code' => 201,
- ];
- }
- }
- /**
- * Displays homepage.
- *
- * @return mixed
- */
- public function actionGetsignature()
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $params=Yii::$app->request->get();
- $signature = $params["signature"];//本地签名
- $timestamp = $params["timestamp"];//时间戳
- unset($params['r'],$params['signature']);
- //valid signature , option
- if($this->checkSignature($params,$timestamp,$signature)){
- return [
- 'message' => 'signature test Ok!',
- 'code' => 100,
- ];
- }else{
- return [
- 'message' => 'signature test fail!',
- 'code' => 201,
- ];
- }
- }
- private static function getSign($params, $appkey, $appSecret, $time)
- {
- $sign = '';
- if (!empty($params)) {
- ksort($params);
- $string = http_build_query($params);
- $result = md5($appkey . $string . $appSecret . $time);
- $sign = strtoupper($result);
- }
- return $sign;
- }
- private function checkSignature($params,$timestamp,$signature)
- {
- define("APP_ID", "disanbo");
- define("APP_SECRET", "di~sanbo1");
- $appkey = APP_ID;
- $appSecret = APP_SECRET;
- $sign= $this->getSign($params, $appkey, $appSecret, $timestamp);
- if( $sign == $signature ){
- //do something
- return true;
- }else{
- return false;
- }
- }
- }
|