Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

321
vendor/wechat/src/WeChat/Core/Authorize.php vendored Executable file
View File

@ -0,0 +1,321 @@
<?php
namespace WeChat\Core;
/**
* Class Authorize 微信授权认证类
* @package WeChat\Core
*/
abstract class Authorize extends Base implements \WeChat\Extend\Authorize
{
/**
* @var string $token 设置微信的认证字符
*/
protected $token = 'dyjj';
/**
* @var string $appID 公众号appid
*/
protected $appid = static::$appid;
/**
* @var string $appScret 公众号appSecret
*/
protected $appSecret = static::$appSecret;
/**
* @var array $config 微信的数据集合
*/
protected $config = [];
/**
* @var array $userInfo 微信的数据集合
*/
protected $userInfo = [];
/**
* @var array $returnData 回复用户的消息数据
*/
protected $returnData = array(
'MsgType' => 'text', // 可选类型[text: 文本|image: 图片|voice: 语音|video: 视频|music: 音乐|news: 图文]
'Title' => '', // 标题
'Content' => '', // 回复的消息内容(换行:在content中能够换行,微信客户端就支持换行显示)
'PicUrl' => '', // 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
'Url' => '', // 点击图文消息跳转链接
'MediaId' => '', // 通过素材管理中的接口上传多媒体文件,得到的id。
'Description' => '', // 视频消息的描述
'MusicURL' => '', // 音乐链接
'HQMusicUrl' => '', // 高质量音乐链接,WIFI环境优先使用该链接播放音乐
'ThumbMediaId' => '', // 缩略图的媒体id,通过素材管理中的接口上传多媒体文件,得到的id
'ArticleCount' => '', // 图文消息个数;当用户发送文本、图片、视频、图文、地理位置这五种消息时,开发者只能回复1条图文消息;其余场景最多可回复8条图文消息
'Articles' => '', // 图文消息信息,注意,如果图文数超过限制,则将只发限制内的条数
);
/**
* 设置与微信对接的TOKEN凭证字符
* Authorize constructor.
* @param string $token 微信开发模式TOKEN字符串
* @param string $appID 微信appid
* @param string $appScret 微信appScret
* @inheritdoc 详细文档:https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=1833550478&lang=zh_CN
*/
public function __construct(string $token,string $appID,string $appScret)
{
// 这里填写的是你在微信上设置的TOKEN,但是必须保证与微信公众平台-接口配置信息一致
if (!empty($token)) $this->token = $token;
if (!empty($appID)) $this->appid = $appID;
if (!empty($appScret)) $this->appSecret = $appScret;
}
/**
* 微信授权
*/
final public function index()
{
// 验证数据或回复用户
(!isset($_REQUEST['echostr'])) ? $this->responseMsg() : $this->valid();
}
/**
* 若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,否则接入失败。
*/
final protected function valid()
{
$echoStr = $_REQUEST['echostr'];
if ($this->checkSignature()) {
echo $echoStr;
exit;
}
}
/**
* 开发者通过检验signature对请求进行校验
* @return bool
*/
final protected function checkSignature()
{
$tmpArr = array($this->token, $_REQUEST['timestamp'], $_REQUEST['nonce']);
sort($tmpArr);
$tmpStr = sha1(implode($tmpArr));
return ($tmpStr == $_REQUEST['signature']) ? true: false;
}
/**
* 公众号的消息推送,回复
*/
final protected function responseMsg()
{
try{
$postStr = file_get_contents("php://input");
if (!empty($postStr)) {
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
// 微信提醒数组
$this->config = json_decode(json_encode($postObj), true);
// 普通授权token
$resToken = Token::gain($this->appid, $this->appSecret);
$this->userInfo = [];
if (isset($resToken['access_token'])){
// 微信用户信息
$this->userInfo = User::newUserInfo($resToken['access_token'], $this->config['FromUserName']);
}
// 逻辑操作,需要更改逻辑的就在这个方法咯~
$this->handle();
// 被动发送消息
Send::trigger($this->config,$this->returnData);
}
}catch (\Exception $exception){
$this->text($exception->getMessage());
}
echo '';
exit;
}
/**
* 首次关注事件
* @return mixed|void
*/
public function follow()
{
// TODO: Implement follow() method.
$sendMsg = '您好,感谢您关注,爱你么么哒~';
$this->text($sendMsg);
}
/**
* 扫码关注事件
* @return mixed|void
*/
public function scanFollow()
{
// TODO: Implement scanFollow() method.
$this->text('扫码关注' . json_encode($this->config));
}
/**
* 点击事件
* @return mixed|void
*/
public function click()
{
// TODO: Implement click() method.
$this->text('这个是用户点击事件~'. json_encode($this->config));
}
/**
* 扫码商品事件
* @return mixed|void
*/
public function scanProduct()
{
// TODO: Implement scanProduct() method.
$this->text('用户商品扫码' . json_encode($this->config));
}
/**
* 扫码事件
* @return mixed|void
*/
public function scan()
{
// TODO: Implement scan() method.
$this->text('扫码进入' . json_encode($this->config));
}
/**
* 用户输入
* @return mixed|void
*/
public function input()
{
// TODO: Implement input() method.
$this->text('用户输入' . json_encode($this->config));
}
/**
* 用户操作方法
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
final public function handle()
{
// TODO: Implement handle() method.
switch ($this->config['MsgType']){
case $this->config['MsgType'] =='text':
$this->input();
break;
case $this->config['Event'] == 'subscribe' :
$params = explode('_', trim($this->config['EventKey'])); // 扫码参数
!isset($params[1]) ?
$this->follow() : // 搜索公众号或推荐公众号关注
$this->scanFollow(); // 扫码关注
break;
case $this->config['Event'] == 'user_scan_product_enter_session': // 用户商品扫码
$this->scanProduct();
break;
case $this->config['Event'] == 'CLICK': // 用户点击事件
$this->click();
break;
case $this->config['Event'] == 'SCAN': // 扫码进入
$this->scan();
break;
}
}
/**
* 发送文本消息
* @param string $content 回复的文本内容
*/
final protected function text(string $content = '这是个友好的回复~')
{
$this->returnData['MsgType'] = __FUNCTION__;
$this->returnData['Content'] = $content;
}
/**
* 发送图片消息
* @param string $mediaId 素材ID
*/
final protected function image(string $mediaId)
{
$this->returnData['MsgType'] = __FUNCTION__;
$this->returnData['MediaId'] = $mediaId;
}
/**
* 发送语音消息
* @param string $mediaId 素材ID
*/
final protected function voice(string $mediaId)
{
$this->returnData['MsgType'] = __FUNCTION__;
$this->returnData['MediaId'] = $mediaId;
}
/**
* 发送视频消息
* @param string $mediaId 素材ID
* @param string $title 视频标题
* @param string $description 视频消息的描述
*/
final protected function video(string $mediaId,string $title = '这是一个标题',string $description = '消息的描述')
{
$this->returnData['MsgType'] = __FUNCTION__;
$this->returnData['MediaId'] = $mediaId;
$this->returnData['Title'] = $title;
$this->returnData['Description'] = $description;
}
/**
* 发送音乐消息
* @param string $title 消息标题
* @param string $description 描述
* @param string $musicURL 音乐链接
* @param string $HQMusicUrl 高清音乐URL
* @param string $ThumbMediaId 缩略图的媒体id,通过素材管理中的接口上传多媒体文件,得到的id
*/
final protected function music(string $title = '这是一个标题',string $description = '消息的描述',
string $musicURL = '', string $HQMusicUrl = '', string $ThumbMediaId = '')
{
$this->returnData['MsgType'] = __FUNCTION__;
$this->returnData['Title'] = $title;
$this->returnData['Description'] = $description;
$this->returnData['MusicURL'] = $musicURL;
$this->returnData['HQMusicUrl'] = $HQMusicUrl;
$this->returnData['ThumbMediaId'] = $ThumbMediaId;
}
/**
* 发送图文消息
* @param array $Articles 图文数组
* @format 格式 $Articles = array(
array(
'Title'=>'标题',
'Description'=>'注释',
'PicUrl'=>'图片地主(含域名的全路径:图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200)',
'Url'=>'点击图文消息跳转链接'
),
);
*/
final protected function news(array $Articles = [])
{
if (!isset($Articles[0]['Title'])) {
echo '';
die;
}
$this->returnData['MsgType'] = __FUNCTION__;
$this->returnData['ArticleCount'] = count($Articles);
$this->returnData['Articles'] = $Articles;
}
}

14
vendor/wechat/src/WeChat/Core/Base.php vendored Executable file
View File

@ -0,0 +1,14 @@
<?php
namespace WeChat\Core;
/**
* Class WxBase 抽象公用静态方法类
* @package wechat
*/
abstract class Base
{
use \WeChat\Extend\Tool;
protected static $appid = 'wx2b29f5846b8d00fa';
protected static $appSecret = 'd8b93b7e2b175b904c435cb493b66ff8';
}

147
vendor/wechat/src/WeChat/Core/Menu.php vendored Executable file
View File

@ -0,0 +1,147 @@
<?php
namespace WeChat\Core;
/**
* Class Menu 微信菜单类
* @package WeChat\Core
*/
class Menu extends Base
{
// 获取菜单
private static $getMenuUrl = 'https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=ACCESS_TOKEN';
// 设置菜单
private static $setMenuUrl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN';
/**
* 获取菜单
* @inheritdoc 详细文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141014
* @param string $accessToken
* @return array|bool
*/
public static function gain(string $accessToken)
{
// 拼装获取菜单链接
$getMenuUrl = str_replace('ACCESS_TOKEN', $accessToken, static::$getMenuUrl);
// 发送获取菜单,获取结果
return self::get($getMenuUrl);
}
/**
* 删除菜单
* @inheritdoc 详细文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015
* @param string $accessToken
* @return array|bool
*/
public static function delete(string $accessToken)
{
// 拼装获取菜单链接
$getMenuUrl = str_replace('ACCESS_TOKEN', $accessToken, static::$getMenuUrl);
// 发送获取菜单,获取结果
return self::get($getMenuUrl);
}
/**
* 设置菜单
* @inheritdoc 详细文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013
* @param string $accessToken
* @param array $menu
例如:$menu =[
[
'type'=> 'click', //
'name'=> '这是第一级button',
'list' => [
[
'type'=> 'view',
'name'=> '百度',
'url' => 'http://www.baidu.com',
]
],
],
[
'type'=> 'miniprogram',
'name'=> 'xx小程序',
'url' => 'http://www.baidu.com',
'appid' => 'asdasdas', 小程序APPID
'pagepath' => '/page/index/index', // 小程序页面链接
]
];
* @return array
*/
public static function set(string $accessToken, array $menu)
{
(!is_array($menu) or count($menu) < 1) && self::error('请设置正确的参数 $menu ~ !');
// 组装参数
$format_param['button'] = self::format($menu);
// 替换token
$setMenuUrl = str_replace('ACCESS_TOKEN', $accessToken, static::$setMenuUrl);
// 生成菜单
return self::post($setMenuUrl, json_encode($format_param, JSON_UNESCAPED_UNICODE));
}
/**
* 格式化菜单数组
* @param array $menu 菜单数组
* @return array
*/
public static function format(array $menu)
{
$button =[];
foreach ($menu as $key => $val) {
if (!isset($val['list'])) {
$button[$key] = static::getTypeParam($val['type'],$val);
} else {
$button[$key]['name'] = $val['name'];
$button[$key]['sub_button'] = static::format($val['list']);
}
}
return $button;
}
/**
* 获取自定义菜单参数
* @param string $type 类型
* @param array $item 数组
* @return array
*/
private static function getTypeParam(string $type,array $item)
{
switch (strtolower($type))
{
case 'click':
return array(
'type' => 'click',
'name' => $item['name'],
'key' => $item['name'], // 关键词
);
break;
case 'view':
return array(
'type' => 'view',
'name' => $item['name'],
'url' => $item['url'], // 原文链接
);
break;
case 'miniprogram': // 小程序
return array(
'type' => 'miniprogram',
'name' => $item['name'], // 菜单名称
'url' => $item['url'], // 小程序链接
'appid' => $item['appid'], // 小程序APPID
'pagepath' => $item['pagepath'], // 小程序页面路径
);
break;
}
}
}

94
vendor/wechat/src/WeChat/Core/QrCode.php vendored Executable file
View File

@ -0,0 +1,94 @@
<?php
namespace WeChat\Core;
include(__DIR__.'/../Lib/phpqrcode.php');
/**
* Class Qrcode 二维码类
* @package wechat
*/
class QrCode extends Base
{
// 获取微信公众二维码(永久/有效时长)
private static $setQrCodeUrl = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN';
// 显示微信公众号二维码
private static $showqrcodeUrl = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=JSAPI_TICKET';
/**
* 生成二维码
* @inheritdoc 文档说明:http://phpqrcode.sourceforge.net/
* @param string $text 二维码内容
* @param bool $filePath 二维码储存路径
* @param string $level 二维码容错机制
* @param int $size 点大小
* @param int $margin 点间距
* @param bool $saveandprint 保存或打印
* @return string|void
*/
public static function create(string $text = '',
bool $filePath = false,
string $level = QR_ECLEVEL_L,
int $size = 6,
int $margin = 2,
bool $saveandprint=false)
{
try {
if ($filePath !== false) {
// Save it to a file
if (!is_dir(dirname($filePath))) {
mkdir(dirname($filePath), 755);
}
}
return \QRcode::png($text,$filePath,$level,$size,$margin,$saveandprint);
} catch (\WeChat\Extend\Json $exception) {
return $exception->getMessage();
}
}
/**
* 创建微信带参二维码生成
* @inheritdoc 详细文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542
* @param string $accessToken 授权TOKEN
* @param string $scene_str 字符串
* @param string $scene_str_prefix 字符串前缀
* @param int $type 二维码类型:(小于等于1) = 有效时长30天 (大于等于2) = 永久
* @return array|bool|mixed
*/
public static function wechat(string $accessToken,string $scene_str, string $scene_str_prefix = 'wene_', int $type = 1)
{
$result = false;
// 验证微信普通token
empty($accessToken) && $accessToken = Token::gain();
//创建加密字符
$strLen = strlen($scene_str) + strlen($scene_str_prefix);
// 验证字符长度
if ($strLen <= 64 and $strLen > 1) {
// 准备参数
$setQrCodeUrl = str_replace('TOKEN', $accessToken, static::$setQrCodeUrl);
$qrCodeParam['action_name'] = "QR_LIMIT_STR_SCENE";
if(intval($type) <= 1){
$qrCodeParam['action_name'] = "QR_STR_SCENE";
$qrCodeParam['expire_seconds'] = 604800;
}
$qrCodeParam['action_info'] = [
'scene'=> ['scene_str'=> $scene_str_prefix . $scene_str],
];
$qrCodeParam = json_encode($qrCodeParam,JSON_UNESCAPED_UNICODE);
// 获取对应数据
$result = self::post($setQrCodeUrl, $qrCodeParam);
if (isset($result['ticket'])) {
$result['showUrl'] = str_replace('JSAPI_TICKET',$result['ticket'],static::$showqrcodeUrl);
}
}
// 返回结果
return $result;
}
}

214
vendor/wechat/src/WeChat/Core/Send.php vendored Executable file
View File

@ -0,0 +1,214 @@
<?php
namespace WeChat\Core;
/**
* Class WxSend 微信推送类
* @package wechat
*/
class Send extends Base
{
// 微信发送模板消息API
private static $setMsgUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN';
// 被动回复微信数据
protected static $triggerConfig;
// 被动回复用户数据
protected static $triggerData;
// 被动回复消息模板
protected static $triggerTemplate;
// 被动回复消息模板公共部分
protected static $triggerTemplateStart = '<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>';
/**
* 被动回复消息
* @param array $triggerConfig 微信消息对象
* @param array $triggerData 用户数据
* @throws \Exception
*/
public static function trigger(array $triggerConfig = [], array $triggerData = [])
{
static::$triggerConfig = $triggerConfig;
static::$triggerData = $triggerData;
try {
static::$triggerTemplateStart = sprintf(static::$triggerTemplateStart, static::$triggerConfig['FromUserName'], static::$triggerConfig['ToUserName'],
time(), static::$triggerData['MsgType']);
static::setTriggerMsgTemplate();
echo static::$triggerTemplate;
die;
} catch (\Exception $exception) {
static::$triggerTemplateStart = sprintf(static::$triggerTemplateStart, static::$triggerConfig['FromUserName'], static::$triggerConfig['ToUserName'],
time(), 'text');
static::$triggerData['Content'] = $exception->getMessage();
static::setTriggerMsgTemplate();
echo static::$triggerTemplate;
die;
}
}
/**
* 主动发送模板消息
* @inheritdoc 详细文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
* @param string $accessToken
* @param string $pushTemplateId 模板ID
* @param string $openid 用户openid
* @param array $pushData 模板参数
* @param string $url 模板消息链接
* @param string $topColor 微信top颜色
* @return array
*/
public static function push(string $accessToken, string $pushTemplateId, string $openid, array $pushData = [],
string $url = '', string $topColor = '#FF0000')
{
// 检测参数
if (empty($pushData) or empty($openid) or empty($pushTemplateId)) {
self::error('请设置正确的参数 $triggerTemplate or $value~ !');
}
// 准备数据
$pushTemplate['template_id'] = $pushTemplateId;
$pushTemplate['touser'] = $openid;
$pushTemplate['url'] = empty($url) ? '' : $url;
$pushTemplate['topcolor'] = empty($topColor) ? '' : $topColor;
$pushTemplate['data'] = $pushData;
$send_url = str_replace('ACCESS_TOKEN', $accessToken, static::$setMsgUrl);
// 发送请求,并返回
return self::post($send_url, json_encode($pushTemplate, JSON_UNESCAPED_UNICODE));
}
/**
* 设置被动消息模板
* @param string $type 属性,可选类型[text: 文本|image: 图片|voice: 语音|video: 视频|music: 音乐|news: 图文]
* @inheritdoc 微信消息文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140543
* @throws \Exception
*/
protected static function setTriggerMsgTemplate()
{
$msgType = static::$triggerData['MsgType'];
switch ($msgType) {
case 'text':
self::setTriggerTextMsgTemplate();
break;
case 'image':
self::setTriggerImageMsgTemplate();
break;
case 'voice':
self::setTriggerVoiceMsgTemplate();
break;
case 'video':
self::setTriggerVideoMsgTemplate();
break;
case 'music':
static::setTriggerMusicMsgTemplate();
break;
case 'news':
static::setTriggerNewsMsgTemplate();
break;
default :
self::setTriggerTextMsgTemplate();
break;
}
}
/**
* 设置文本消息
* @throws \Exception
*/
private static function setTriggerTextMsgTemplate()
{
$msgTemplate = '<Content><![CDATA[%s]]></Content><FuncFlag>0</FuncFlag>';
static::$triggerTemplate = '<xml>' . static::$triggerTemplateStart . $msgTemplate . '</xml>';
static::$triggerTemplate = sprintf(static::$triggerTemplate, static::$triggerData['Content']);
}
/**
* 设置图片消息
* @throws \Exception
*/
private static function setTriggerImageMsgTemplate()
{
$msgTemplate = '<Image><MediaId><![CDATA[%s]]></MediaId></Image>';
static::$triggerTemplate = '<xml>' . static::$triggerTemplateStart . $msgTemplate . '</xml>';
static::$triggerTemplate = sprintf(static::$triggerTemplate, static::$triggerData['MediaId']);
}
/**
* 设置语音消息
* @throws \Exception
*/
private static function setTriggerVoiceMsgTemplate()
{
$msgTemplate = '<Voice><MediaId>< ![CDATA[%s]]></MediaId></Voice>';
static::$triggerTemplate = '<xml>' . static::$triggerTemplateStart . $msgTemplate . '</xml>';
static::$triggerTemplate = sprintf(static::$triggerTemplate, static::$triggerData['MediaId']);
}
/**
* 设置视频消息
* @throws \Exception
*/
private static function setTriggerVideoMsgTemplate()
{
$msgTemplate = '<Video><MediaId><![CDATA[%s]]></MediaId><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description></Video>';
static::$triggerTemplate = '<xml>' . static::$triggerTemplateStart . $msgTemplate . '</xml>';
static::$triggerTemplate = sprintf(static::$triggerTemplate, static::$triggerData['MediaId'], static::$triggerData['Title'], static::$triggerData['Description']);
}
/**
* 设置音乐消息
* @throws \Exception
*/
private static function setTriggerMusicMsgTemplate()
{
$msgTemplate = '<Music>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<MusicUrl><![CDATA[%s]]></MusicUrl>
<HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
</Music>';
static::$triggerTemplate = '<xml>' . static::$triggerTemplateStart . $msgTemplate . '</xml>';
static::$triggerTemplate = sprintf(static::$triggerTemplate, static::$triggerData['Title'], static::$triggerData['Description'],
static::$triggerData['MusicUrl'], static::$triggerData['HQMusicUrl'], static::$triggerData['ThumbMediaId']);
}
/**
* 设置图文消息
* @throws \Exception
*/
private static function setTriggerNewsMsgTemplate()
{
$newCount = count(static::$triggerData['Articles']);
if ($newCount < 1) throw new \Exception('图文消息发送失败,请检查数据结构~');
try {
$msgTemplate = "<ArticleCount>'.$newCount.'</ArticleCount>";
$msgTemplate .= "<Articles>";
foreach (static::$triggerData['Articles'] as $article) {
$msgTemplate .= '<item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]]></Url>
</item>';
$msgTemplate = sprintf($msgTemplate, $article['Title'], $article['Description'],
$article['PicUrl'], $article['Url']);
}
$msgTemplate .= '</Articles>';
static::$triggerTemplate = '<xml>' . static::$triggerTemplateStart . $msgTemplate . '</xml>';
} catch (\Exception $exception) {
throw new \Exception('图文消息发送失败,错误信息:' . $exception->getMessage());
}
}
}

57
vendor/wechat/src/WeChat/Core/Template.php vendored Executable file
View File

@ -0,0 +1,57 @@
<?php
namespace WeChat\Core;
/**
* Class WxTemplate 微信模板类
* @package wechat
*/
class Template extends Base
{
// 微信获取所有模板api
private static $getTemplateUrl = 'https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=TOKEN';
/**
* 格式化消息模板内容
* @param array $template 模板内容
* @return array 消息模板内容
*/
public static function format($template = [])
{
$param = self::trim_template($template['content']);
$template['param'] = [
'touser' => '', // 用户OPENID
'template_id' => $template['template_id'], //模板ID
'url' => '', // 跳转的url地址
'topcolor' => '',
'data' => $param, //模板必须参数
];
return $template;
}
/**
* 获取所有消息模板内容
* @inheritdoc 详细文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
* @param string $accessToken 微信token
* @return array
*/
public static function gain(string $accessToken)
{
static::$getTemplateUrl = str_replace('TOKEN',$accessToken,static::$getTemplateUrl);
return self::get(static::$getTemplateUrl);
}
/**
* 获取模板需要的参数name
* @param string $string 过滤包含参数的字符串
* @return array 不带其它字符的参数数组
*/
private static function trim_template(string $string)
{
$string = preg_replace('/([\x80-\xff]*)/i', '', $string);
$trim = array(" ", " ", "\t", "\n", "\r", '.DATA', '}}');
$arr = explode('{{', str_replace($trim, '', $string));
unset($arr[0]);
return array_values($arr);
}
}

71
vendor/wechat/src/WeChat/Core/Ticket.php vendored Executable file
View File

@ -0,0 +1,71 @@
<?php
namespace WeChat\Core;
/**
* Class WxTicket 微信ticket类 含签名生成
* @package wechat
*/
class Ticket extends Base
{
// 微信ticket (jsapi)
private static $getTicketUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi';
/**
* 设置微信ticket
* @param string $accessToken 微信普通token
* @return bool 微信 ticket|false
*/
public static function gain(string $accessToken)
{
$param = \WeChat\Extend\File::param('ticket');
if ($param === null or empty($param)) {
// 准备数据
static::$getTicketUrl = str_replace('ACCESS_TOKEN',$accessToken,static::$getTicketUrl);
$result = self::get(static::$getTicketUrl);
// 返回数据
isset($result['ticket']) && \WeChat\Extend\File::param('ticket', $result);
return $result;
} else {
return $param['ticket'];
}
}
/**
* 获取微信JSDK
* @param string $ticket 获取微信JSDK签名
* @param string $redirect_url 微信JSDK
* @return mixed
*/
public static function sign(string $ticket, string $redirect_url = '')
{
$url = empty($redirect_url) ? $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : $redirect_url;
$timestamp = time();
$nonceStr = self::createNonceStr();
$string = 'jsapi_ticket=' . $ticket . '&noncestr=' . $nonceStr . '&timestamp=' . $timestamp . '&url=' . $url;
$param['rawString'] = $string;
$param['signature'] = sha1($param['rawString']);
$param['nonceStr'] = $nonceStr;
$param['timestamp'] = $timestamp;
$param['url'] = $url;
return $param;
}
/**
* 创建随机字符微信版本
* @param int $length
* @return string
*/
private static function createNonceStr($length = 16)
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
}

49
vendor/wechat/src/WeChat/Core/Token.php vendored Executable file
View File

@ -0,0 +1,49 @@
<?php
namespace WeChat\Core;
/**
* Class WxToken 微信Token类
* @package wechat
*/
class Token extends Base
{
// 获取token API地址
private static $getTokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET';
/**
* [gain 获取微信access_token]
* @param string $appid [微信AppID]
* @param string $appSecret [微信AppSecret]
* @return [string] [微信access_token]
*/
public static function gain()
{
$appid = static::$appid;
$appSecret = static::$appSecret;
$param = \WeChat\Extend\File::param('access_token');
if ($param === null or (isset($param['time']) and time() - $param['time'] > 7150)) {
// 进行微信AppID 和 AppSecret的验证
if(empty($appid) or empty($appSecret)){
self::error('请设置管理端微信公众号开发者APPID 和 APPSECRET~ !');
}
// 获取参数验证规则
if (strlen(trim($appid)) != 18 or strlen(trim($appSecret)) != 32) {
self::error('请设置正确格式的微信公众号开发者APPID 和 APPSECRET~ !');
}
// 准备数据
static::$getTokenUrl = str_replace('APPID', $appid, static::$getTokenUrl);
static::$getTokenUrl = str_replace('APPSECRET', $appSecret, static::$getTokenUrl);
// 返回结果
$result = self::get(static::$getTokenUrl);
isset($result['access_token']) && \WeChat\Extend\File::param('access_token', $result);
return $result;
} else {
return $param['access_token'];
}
self::error('扩展文件夹权限不足~ !');
}
}

98
vendor/wechat/src/WeChat/Core/User.php vendored Executable file
View File

@ -0,0 +1,98 @@
<?php
namespace WeChat\Core;
/**
* Class WxUser 微信用户类
* @package wechat
*/
class User extends Base
{
// 第一步:用户同意授权,获取code
private static $getCodeUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_userinfo&state=state&connect_redirect=1#wechat_redirect';
// 第二步:通过code换取网页授权access_token
private static $getOpenIdUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code';
// 第三步:拉取用户信息(需scope为 snsapi_userinfo)
private static $getUserInfoUrl = 'https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN';
// 第四步:拉取用户信息(普通access_token版)
private static $getUserInfoUrlByToken = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN';
/**
* []
* @param string $appid []
*
*/
/**
* code 重载http,获取微信授权 *
* @header 重载链接获取code
*/
public static function code()
{
empty(static::$appid) && self::error('请设置管理端微信公众号开发者APPID ~ !');
//当前域名
$service_url = urlencode($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
static::$getCodeUrl = str_replace('APPID',static::$appid,static::$getCodeUrl);
static::$getCodeUrl = str_replace('REDIRECT_URI',$service_url,static::$getCodeUrl);
self::header(static::$getCodeUrl);
}
/**
* 获取用户 OPENID
* @param string $code 微信授权CODE
* @param bool $type true:获取用户信息 | false:用户openid
* @return array 用户信息|用户openid
*/
public static function openid(string $code, bool $type = false)
{
//验证参数
(empty(static::$appid) or empty(static::$appSecret)) && self::error('请设置管理端微信公众号开发者APPID 和 APPSECRET~ !');
empty($code) && self::error('请验证是否传了正确的参数 code ~ !');
//获取用户数据
static::$getOpenIdUrl = str_replace('APPID',static::$appid,static::$getOpenIdUrl);
static::$getOpenIdUrl = str_replace('SECRET',static::$appSecret,static::$getOpenIdUrl);
static::$getOpenIdUrl = str_replace('CODE',$code,static::$getOpenIdUrl);
$result = self::get(static::$getOpenIdUrl);
return $type == false ? $result : self::userinfo($result['access_token'], $result['openid']);
}
/**
* 获取用户信息(通过code换取网页授权access_token版)
* @param string $access_token 授权获取用户关键参数:access_token
* @param string $openid 用户openid
* @return array
*/
public static function userInfo(string $access_token, string $openid)
{
(empty($access_token) or empty($openid)) && self::error('getOpenid()方法设置参数~ !');
static::$getUserInfoUrl = str_replace('ACCESS_TOKEN',$access_token,static::$getUserInfoUrl);
static::$getUserInfoUrl = str_replace('OPENID',$openid,static::$getUserInfoUrl);
return self::get(static::$getUserInfoUrl);
}
/**
* 获取用户信息(普通ACCESS_TOKEN获取版)
* @param string $access_token 普通access_token
* @param string $openid 用户openid
* @return array
*/
public static function newUserInfo(string $openid)
{
(empty(static::$access_token) or empty($openid)) && self::error('getOpenid()方法设置参数~ !');
static::$getUserInfoUrlByToken = str_replace('ACCESS_TOKEN',static::$access_token,static::$getUserInfoUrlByToken);
static::$getUserInfoUrlByToken = str_replace('OPENID',$openid,static::$getUserInfoUrlByToken);
return self::get(static::$getUserInfoUrlByToken);
}
}

57
vendor/wechat/src/WeChat/Extend/Authorize.php vendored Executable file
View File

@ -0,0 +1,57 @@
<?php
namespace WeChat\Extend;
/**
* 微信授权接口
* Interface Authorize
* @package WeChat\Extend
*/
interface Authorize
{
/**
* 首次关注
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function follow();
/**
* 扫码关注
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function scanFollow();
/**
* 点击事件
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function click();
/**
* 扫描商品
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function scanProduct();
/**
* 扫码事件
* @return mixed
*/
public function scan();
/**
* 用户输入
* @return mixed
*/
public function input();
}

81
vendor/wechat/src/WeChat/Extend/File.php vendored Executable file
View File

@ -0,0 +1,81 @@
<?php
namespace WeChat\Extend;
/**
* Class File 微信存储类
* @package wechat\lib
*/
class File
{
/**
* 定义常量 / 路径连接符
*/
private static $ext = '/';
/**
* 存储对象文件,可扩展
* @param string $var
* @param array $val
* @return null
*/
public static function param(string $var, array $val = [])
{
$file_path = self::mkdir('param');
$fileCont = json_decode(file_get_contents($file_path), true);
if(empty($fileCont) and empty($val)) return null;
if(!empty($val) and !empty($var)){
$val['time'] = time();
$fileCont[$var] = $val;
file_put_contents($file_path,json_encode($fileCont));
}
if(!empty($val) and empty($var)){
if ($fileCont[$var]['time'] - time() <= 7100){
unset($fileCont[$var]['time']);
if (!empty($fileCont[$var])) return $fileCont[$var];
}
return null;
}
}
/**
* 支付日志
* @param string $type
* @param array $param
* @return mixed
*/
public static function paylog(string $type = 'wechat', array $param = [])
{
$file_path = self::mkdir('wechat');
if (!empty($type) and empty($param)) {
return json_decode(file_get_contents($file_path), true);
}
$data = '['.date('Y-m-d H:i:s').'] => '.json_encode($param) . PHP_EOL;
file_put_contents($file_path, $data, FILE_APPEND);
}
/**
* 创建日志类型文件
* @param string $type
* @return string
*/
private static function mkdir(string $type = 'param')
{
$file_dir = dirname(__FILE__) . static::$ext . 'log' ;
(!is_dir($file_dir)) && mkdir($file_dir, 0755);
$file_dir .= static::$ext . date('Y-m-d-H') . static::$ext;
if ($type == 'param') {
$file_dir = dirname(__FILE__) . static::$ext . 'log' . static::$ext . 'param' . static::$ext;
}
$file_name = $type . '.log';
(!is_dir($file_dir)) && mkdir($file_dir, 0755);
if (!is_file($file_dir . $file_name)) {
file_put_contents($file_dir . $file_name, '');
}
return $file_dir . $file_name;
}
}

59
vendor/wechat/src/WeChat/Extend/Json.php vendored Executable file
View File

@ -0,0 +1,59 @@
<?php
namespace WeChat\Extend;
use Throwable;
/**
* Class Json json输出类
* @package wechat\lib
*/
class Json extends \Exception
{
public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* 请求失败
* @param string $msg
*/
public static function error(string $msg = '请求失败')
{
self::return_abnormal(400, $msg);
}
/**
* 请求成功
* @param string $msg 返回消息
* @param array $data 返回data数据
*/
public static function success(string $msg = '请求成功', array $data = [])
{
self::return_abnormal(200, $msg, $data);
}
/**
* 输出JSON
* @param int $code 状态码
* @param string $msg 原因
* @param array $data 输出数据
*/
public static function return_abnormal(int $code,string $msg,array $data = [])
{
$code_state = $code == 200 ? 'OK' : 'Bad Request';
$param = [
'code' => $code,
'msg' => $msg,
'data' => $data,
];
header("HTTP/1.1 " . $code . " " . $code_state);
header('Content-Type:application/json;charset=utf-8');
if ($param !== null) {
echo json_encode($param, JSON_UNESCAPED_UNICODE);
}
exit();
}
}

119
vendor/wechat/src/WeChat/Extend/Request.php vendored Executable file
View File

@ -0,0 +1,119 @@
<?php
namespace WeChat\Extend;
/**
* Class Request 请求类
* @package wechat\lib
*/
class Request
{
/**
* 支持请求类型
* @var array $methods
*/
private static $methods = ['get','post'];
/**
* 发送 header 请求
* @param string $url 请求链接
* @param array $params 请求参数
*/
public static function header(string $url,array $params = []):void
{
if (!empty($params)) $url .= static::ToUrlParams($params);
header('Location: ' . $url);
exit();
}
/**
* 发送 <script>window.top.location.href</script> 请求
* @param string $url
* @param array $params
*/
public static function jump(string $url,array $params = [])
{
if (!empty($params)) $url .= static::ToUrlParams($params);
exit( '<script>window.top.location.href='.$url.'</script>');
}
/**
* 发送curl请求
* @param string $method 【类型 : get | post】
* @param string $url 请求链接
* @param array $params 请求参数
* @return array
*/
public static function request(string $method,string $url, $params = []):array
{
$method = strtolower($method);
$isHttp = stristr($url,'https') ? true : false;
if (!in_array($method,static::$methods)) Json::error('请求类型错误~');
if ($method === 'get' and !empty($params)) $url .= static::ToUrlParams($params);
return static::curl_request($url,$isHttp,$method,$params);
}
/**
* [curl_request 发送http请求]
* @param [url] $url [请求地址]
* @param boolean $https [是否使用HTTPS]
* @param string $method [请求方式:GET / POST]
* @param [array] $data [post 数据]
* @return [result] [成功返回对方返回的结果,是非返回false]
*/
public static function curl_request($url, $https = false, $method = 'get', $data = null)
{
/**************** 初始化curl ******************/
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //结果为字符串且输出到屏幕上
/**************** 发送 https请求 ******************/
if ($https === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
/******** 发送 POST 请求 类型为:application/x-www-form-urlencoded **********/
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
// 所需传的数组用 http_build_query() 函数处理一下,就可以传递二维数组了
if (is_array($data) and count($data) > 0) $data = http_build_query($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
}
/**************** 发送请求 ******************/
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$url_status = curl_getinfo($ch);
/**************** 关闭连接 并 返回数据 ******************/
curl_close($ch);
if (intval($url_status["http_code"]) == 200){
if (json_decode($result,true) != false){
return json_decode($result,true);
}
return $result;
}
return false;
}
/**
*
* 拼接签名字符串
* @param array $urlObj
*
* @return 返回已经拼接好的字符串
*/
public static function ToUrlParams($urlObj)
{
$buff = "?";
foreach ($urlObj as $k => $v) {
if ($k != "sign") {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
}

179
vendor/wechat/src/WeChat/Extend/Tool.php vendored Executable file
View File

@ -0,0 +1,179 @@
<?php
namespace WeChat\Extend;
/**
* Trait Tool 工具类
* @package wechat\lib
*/
trait Tool
{
/**
* 接口 json 成功输出
* @param string $msg 输出内容,输出参数~
* @param array $data
*/
public static function success($msg = '操作成功', array $data = [])
{
if (is_array($msg)){
Json::success('操作成功~', $data);
}
Json::success($msg, $data);
}
/**
* 接口 json 失败输出
* @param string $msg
*/
public static function error(string $msg = '操作失败')
{
Json::error($msg);
}
/**
* 重载路由
* @param string $url
* @param array $params
*/
public static function header(string $url, array $params = []): void
{
Request::header($url, $params);
}
/**
* curl 发送 POST 请求
* @param string $url
* @param array $params
* @return array
*/
public static function post(string $url,$params = [])
{
return Request::request('POST',$url,$params);
}
/**
* curl 发送 GET 请求
* @param string $url
* @param array $params
* @return array
*/
public static function get(string $url,array $params = [])
{
return Request::request('GET',$url,$params);
}
/**
* url拼接数组
* @param array $params
* @return string
*/
public static function url_splice_array(array $params = [])
{
$buff = "";
foreach ($params as $k => $v) {
if ($k != "sign") {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
* 创建唯一字符
* @param string $strBlur 原字符
* @param string $strType 加密方式 :[w所有|s字符|d数字]
* @param int $strLen 返回字符长度,建议大于16位
* @return string 字符串
*/
public static function randOnlyStr(string $strBlur = '',string $strType = 'w',int $strLen = 18):string
{
$dStr = '0123456789';
$sStr = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$wStr = '!$&()*,/:;=?@-._~';
$strBlurLen = (strlen(static::uniqueString($strBlur)) + 1) == 1 ? 0 : strlen(static::uniqueString($strBlur)) + 1;
$strSuffix = $strBlurLen > 0 ? '#'.static::uniqueString($strBlur) : '';
switch ($strType)
{
case 's': # 字符串
return static::getGapStrByStr($sStr,$strLen - $strBlurLen).$strSuffix;
break;
case 'd': # 数字
return static::getGapStrByStr($dStr,$strLen - $strBlurLen).$strSuffix;
break;
case 'w': # 匹配包括下划线的任何单词字符。等价于“[A-Za-z0-9_]”。
return static::getGapStrByStr($dStr.$sStr.$wStr,$strLen - $strBlurLen).$strSuffix;
break;
default : # 默认大小写字母
return static::getGapStrByStr($sStr,$strLen - $strBlurLen).$strSuffix;
break;
}
}
/**
* 获取对应字符
* @param string $str 字符串
* @param int $strLen 长度
* @return string 随机字符串
*/
public static function getGapStrByStr(string $str = '', int $strLen = 18)
{
static $newStr = '';
static $i = 0;
if ($i < $strLen)
{
$newStr .= $str[rand(0,strlen($str))];
$i ++;
static::getGapStrByStr($str,$strLen);
}
return $newStr;
}
/**
* 生成唯一字符串
* @param $type $type 类型
* @return string 字符串
*/
public static function uniqueString(string $type)
{
return bin2hex($type);
}
/**
* 获取唯一字符串类型
* @param $string $string 唯一字符串
* @return bool|string 返回结果:字符串或者false
*/
public static function uniqueType(string $string)
{
return hex2bin($string);
}
/**
* 小程序检验数据的真实性,并且获取解密后的明文.
* @param string $appID 加密的用户数据
* @param string $sessionKey 与用户数据一同返回的初始向量
* @param string $encryptedData 解密后的原文
* @param string $iv 成功0,失败返回对应的错误码
* @return string
*/
public static function decryptData(string $appID, string $sessionKey, string $encryptedData, string $iv )
{
if (strlen($sessionKey) != 24) return '4';
if (strlen($iv) != 24) return '3';
$aesKey = base64_decode($sessionKey);
$aesIV = base64_decode($iv);
$aesCipher = base64_decode($encryptedData);
$result = openssl_decrypt($aesCipher,"AES-128-CBC",$aesKey,1,$aesIV);
$dataObj = json_decode($result,true);
if( $dataObj == NULL ) return '2';
if( $dataObj['watermark']['appid'] != $appID ) return '1';
return $result;
}
}

View File

@ -0,0 +1 @@
{"access_token":{"access_token":"22_TkrZweCYc9K1gZtrP7YjI-rKHTeaWhEfWS6XWVd1MbGHdPXLd72rFNx3ziElXYKoFKwYVUOiAzHrUQPvlEvxdRCElu03JlDSJWkdF6U3z6AsPq44YQLVFinkSewiRd6h74TKo6Y_Xjn_Bo3sUJCcAGAZOH","expires_in":7200,"time":1561616075}}

3310
vendor/wechat/src/WeChat/Lib/phpqrcode.php vendored Executable file

File diff suppressed because it is too large Load Diff