78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use app\common\library\Sms as Smslib;
|
|
use app\common\model\User;
|
|
use think\Hook;
|
|
use think\Request;
|
|
/**
|
|
* 手机短信接口
|
|
*/
|
|
class Share
|
|
{
|
|
protected $noNeedLogin = '*';
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function send()
|
|
{
|
|
exit;
|
|
$url = Request::instance()->param("url");
|
|
// $url = 'http://www.baidu.com';
|
|
$access_tokenurl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxae874d12ca3f56b8&secret=0984255faae9d7c0c8a9926aa396d22b';
|
|
$tokenBase = $this->http_get($access_tokenurl);
|
|
$ticketurl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$tokenBase['access_token'].'&type=jsapi';
|
|
$ticketbase = $this->http_get($ticketurl);
|
|
//生成随机字符串
|
|
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
$str = "";
|
|
for ($i = 0; $i < 16; $i++) {
|
|
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
|
}
|
|
|
|
$wxdata['noncestr'] = $str;
|
|
$wxdata['jsapi_ticket'] = $ticketbase['ticket'];
|
|
$wxdata['timestamp'] = time();
|
|
$wxdata['url'] = $url;
|
|
|
|
$string = "jsapi_ticket=".$wxdata['jsapi_ticket']."&noncestr=".$wxdata['noncestr']."×tamp=".$wxdata['timestamp']."&url=".$wxdata['url'];
|
|
|
|
$signature = sha1($string);
|
|
|
|
$signPackage = array(
|
|
// "appId" => 'wxae874d12ca3f56b8',
|
|
"nonceStr" => $wxdata['noncestr'],
|
|
"timestamp" => $wxdata['timestamp'],
|
|
"url" => $wxdata['url'],
|
|
"signature" => $signature,
|
|
// "rawString" => $string
|
|
);
|
|
|
|
return json($signPackage);
|
|
}
|
|
|
|
public function http_get($url, $header = [])
|
|
{
|
|
if (empty($header)) {
|
|
$header = [
|
|
"Content-type:application/json;",
|
|
"Accept:application/json"
|
|
];
|
|
}
|
|
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
$response = curl_exec($curl);
|
|
curl_close($curl);
|
|
$response = json_decode($response, true);
|
|
|
|
return $response;
|
|
}
|
|
}
|