调整code及access_token生成方式

This commit is contained in:
qinzongqing 2023-04-17 16:46:23 +08:00
parent 03c0dfec30
commit 5e032d19fd
3 changed files with 11 additions and 19 deletions

View File

@ -145,15 +145,6 @@ class ControllerBase extends Phalcon\Mvc\Controller{
return $configData; return $configData;
} }
/**
* 随机生成字符串
*/
function _get_act_code($digit=32){
$str = 'abcdefghijklmnopqrstuvwxyz0123456789';
$code = substr(str_shuffle($str), 0, $digit);
return $code;
}
/** /**
* 校验是否有收到请求数据 * 校验是否有收到请求数据
*/ */

View File

@ -17,14 +17,14 @@ class Oauth2Controller extends ControllerBase{
* http://weapp.wemediacn.net/d/tiffany/api/oauth2/test?qaz=wsx * http://weapp.wemediacn.net/d/tiffany/api/oauth2/test?qaz=wsx
*/ */
function testAction(){ function testAction(){
$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/code"; //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/code";
//$url = "http://127.0.0.1/tiffany/api/oauth2/code?qaz=wsx"; //$url = "http://127.0.0.1/tiffany/api/oauth2/code?qaz=wsx";
//$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/accesstoken"; //$url = "http://wxapp.wemediacn.com/smsoauth2_qa/api/oauth2/accesstoken";
//$url = "http://127.0.0.1/tiffany/api/oauth2/accesstoken?qaz=wsx"; $url = "http://127.0.0.1/tiffany/api/oauth2/accesstoken?qaz=wsx";
$post_arr = array(); $post_arr = array();
$post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7"; $post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7";
$post_arr['appsecrect'] = "b82015bd-8d4c-4df8-87a8-c25477a8976f"; $post_arr['appsecrect'] = "b82015bd-8d4c-4df8-87a8-c25477a8976f";
$post_arr['code'] = "b4ed9dabbe1f4dd5bc824046d37922d5"; $post_arr['code'] = "b877e2d843ef2c21fc28e7126423d217";
$post_json = json_encode($post_arr); $post_json = json_encode($post_arr);
$result = $this->__http_post_request($url, $post_json, true); $result = $this->__http_post_request($url, $post_json, true);
print_r($result); die; print_r($result); die;
@ -70,7 +70,7 @@ class Oauth2Controller extends ControllerBase{
$TempCode->LastModifiedTime = $this->current_datetime; $TempCode->LastModifiedTime = $this->current_datetime;
} }
//其他字段 //其他字段
$TempCode->Code = $code = $this->_get_act_code(32); $TempCode->Code = $code = md5(uniqid(mt_rand(), true));
$TempCode->IsUsed = 0; $TempCode->IsUsed = 0;
$TempCode->ExpireTime = date("Y-m-d H:i:s", $this->current_time+300); $TempCode->ExpireTime = date("Y-m-d H:i:s", $this->current_time+300);
//如果保存失败 //如果保存失败
@ -196,7 +196,7 @@ class Oauth2Controller extends ControllerBase{
if(empty($AccessToken)){ if(empty($AccessToken)){
//准备新增AccessToken //准备新增AccessToken
$AccessToken = new AccessToken(); $AccessToken = new AccessToken();
$AccessToken->Id = $this->_get_act_code(32); $AccessToken->Id = md5(uniqid(mt_rand(), true));
$AccessToken->AppId = $appid; $AccessToken->AppId = $appid;
$AccessToken->PrevAccessToken = null; $AccessToken->PrevAccessToken = null;
$AccessToken->CreateTime = $this->current_datetime; $AccessToken->CreateTime = $this->current_datetime;
@ -216,7 +216,7 @@ class Oauth2Controller extends ControllerBase{
} }
} }
//其他字段 //其他字段
$AccessToken->AccessToken = $access_token = $this->_get_act_code(32); $AccessToken->AccessToken = $access_token = md5(uniqid(mt_rand(), true));
$AccessToken->ExpireTime = date("Y-m-d H:i:s", $this->current_time+14400); $AccessToken->ExpireTime = date("Y-m-d H:i:s", $this->current_time+14400);
//如果保存失败 //如果保存失败
if(!($AccessToken->save())){ if(!($AccessToken->save())){

View File

@ -45,7 +45,7 @@ class SmsController extends ControllerBase{
$post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7"; $post_arr['appid'] = "0e355010-67b9-4aa6-a53f-c92c972094a7";
$post_arr['mobile'] = "13501882318"; $post_arr['mobile'] = "13501882318";
$post_arr['access_token'] = "9d21508a7531430c843cff8063dccb1c"; $post_arr['access_token'] = "9d21508a7531430c843cff8063dccb1c";
$post_arr['access_token'] = "ycq9t62einm7usfah1vk4z38djxp5gwl"; $post_arr['access_token'] = "520aec4ea5b42e1bc6d4549eeac26c14";
$post_arr['content'] = "[$=yzm=$]、[$=params1=$]、[$=params2=$]、[$=params3=$]、[$=params4=$]、[$=params5=$]"; $post_arr['content'] = "[$=yzm=$]、[$=params1=$]、[$=params2=$]、[$=params3=$]、[$=params4=$]、[$=params5=$]";
$post_arr['format'] = ""; $post_arr['format'] = "";
$post_arr['len'] = -1; $post_arr['len'] = -1;
@ -57,10 +57,11 @@ class SmsController extends ControllerBase{
$post_arr['params5'] = 5; $post_arr['params5'] = 5;
$post_arr['params6'] = 6; $post_arr['params6'] = 6;
$post_arr['is_resend'] = true; $post_arr['is_resend'] = true;
$post_arr['min_id'] = 4115398953;
$post_arr['min_id'] = 4116344287;
$post_arr['min_id'] = 4116344229;
$post_arr['min_id'] = 0; $post_arr['min_id'] = 0;
$post_arr['min_id'] = 4121165901;
$post_arr['min_id'] = 4120793819;
$post_arr['min_id'] = 4121165413;
$post_arr['min_id'] = 4121165408;
$post_json = json_encode($post_arr); $post_json = json_encode($post_arr);
$result = $this->__http_post_request($url, $post_json, true); $result = $this->__http_post_request($url, $post_json, true);
print_r($result); die; print_r($result); die;