69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
||
header("Access-Control-Allow-Origin: *");
|
||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
||
header("Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With");
|
||
header("Access-Control-Allow-Credentials: true");
|
||
header("Content-Type: text/html; charset=utf-8");
|
||
|
||
|
||
use phprs\util\Verify;
|
||
use phprs\util\exceptions\Forbidden;
|
||
use phprs\util\Logger;
|
||
use phprs\util\exceptions\NotFound;
|
||
use phprs\ezsql\Sql;
|
||
use phprs\util\exceptions\BadRequest;
|
||
|
||
require_once 'apiBase.php';
|
||
|
||
/**
|
||
*
|
||
* 微信相关接口
|
||
* @path("/weixin")
|
||
*/
|
||
class weixinTools extends apiBase
|
||
{
|
||
/**
|
||
* 获得微信分享参数信息(错误代码:12701-12750)
|
||
* @route({"POST","/wx_share_info"})
|
||
* @param({"appid","$._POST.appid"}) 所属公众号
|
||
* @param({"devkey","$._POST.devkey"}) 外部应用ID
|
||
* @param({"sid","$._POST.sid"}) 临时会员ID
|
||
* @param({"scode","$._POST.scode"}) 客户端票据
|
||
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
||
*/
|
||
public function getWeixinShareInfo($appid = '', $devkey = '', $sid = '', $scode = '')
|
||
{
|
||
// 验证公共参数是否合法
|
||
parent::init($appid, $devkey, $sid, $scode);
|
||
$verify_result = parent::verify();
|
||
|
||
if (!is_error_api($verify_result))
|
||
{
|
||
$refererUrl = $_SERVER['HTTP_REFERER'];
|
||
if ($this->userInfo["auth_type"] == AUTHTYPE_WECHAT)
|
||
{
|
||
$account = array('key' => $this->marketInfo['weixin_appid']);
|
||
$weixin = new WeiXinAccount($account);
|
||
$share_config = $weixin->getAjaxJssdkConfig($refererUrl, $this->db, $this->db);
|
||
if (!is_error($share_config) && !empty($share_config))
|
||
return new returnObject(0, 0, '', $share_config);
|
||
else
|
||
return new returnObject(1, 12702, '获取微信分享参数失败。');
|
||
}
|
||
else
|
||
return new returnObject(1, 12701, '只有微信登录状态下能进行分享。');
|
||
}
|
||
else
|
||
return $verify_result;
|
||
}
|
||
|
||
|
||
/** @inject("ioc_factory") */
|
||
private $factory;
|
||
/**
|
||
* @property({"default":"@db"})
|
||
* @var PDO
|
||
*/
|
||
public $db;
|
||
// 此处删除了代码
|
||
} |