This commit is contained in:
2025-10-29 15:32:26 +08:00
parent d90614805b
commit b7462657cd
78921 changed files with 2753938 additions and 71 deletions

View File

@@ -6,17 +6,24 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: newshop_php container_name: newshop_php
restart: always restart: always
extra_hosts:
- "host.docker.internal:host-gateway" # 支持主机名解析
environment: environment:
- PHP_ENV=development - PHP_ENV=development
- APP_ENV=development - APP_ENV=development
- APP_DEBUG=true - APP_DEBUG=true
- XDEBUG_CONFIG=client_host=host.docker.internal client_port=9003
- PHP_IDE_CONFIG=serverName=docker-php
ports: ports:
- "9000:9000" # PHP-FPM - "9000:9000" # PHP-FPM
- "9003:9003" # Xdebug
volumes: volumes:
- ./src:/var/www/html - ./src:/var/www/html
# 更新下载源列表以加速apt-get # 更新下载源列表以加速apt-get
- ./docker/debian/sources.list:/etc/apt/sources.list:ro - ./docker/debian/sources.list:/etc/apt/sources.list:ro
- ./docker/php/php.ini:/usr/local/etc/php/php.ini:ro - ./docker/php/php.ini:/usr/local/etc/php/php.ini:ro
- ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- xdebug_logs:/tmp # Xdebug 日志目录
depends_on: depends_on:
- db - db
networks: networks:
@@ -88,6 +95,7 @@ services:
volumes: volumes:
mysql_db_data: mysql_db_data:
redis_data: redis_data:
xdebug_logs:
networks: networks:
newshop-net: newshop-net:

View File

@@ -1,65 +1,76 @@
# 使用官方PHP镜像 # 使用官方PHP镜像
FROM php:7.4.33-fpm FROM php:7.4.33-fpm
# 拷贝本地的 sources.list 文件以加速 apt-get # 设置工作目录
COPY ./sources.list /etc/apt/sources.list WORKDIR /var/www/html
# 安装系统依赖 # 拷贝本地的 sources.list 文件以加速 apt-get
RUN apt-get update && apt-get install -y \ COPY ./sources.list /etc/apt/sources.list
git \
vim \ # 安装系统依赖
curl \ RUN apt-get update && apt-get install -y \
libpng-dev \ git \
libonig-dev \ curl \
libxml2-dev \ vim \
libssl-dev \ libpng-dev \
zip \ libonig-dev \
unzip \ libxml2-dev \
libzip-dev \ libssl-dev \
default-mysql-client \ zip \
libfreetype6-dev \ unzip \
libjpeg62-turbo-dev \ libzip-dev \
libpng-dev \ default-mysql-client \
&& rm -rf /var/lib/apt/lists/* libfreetype6-dev \
libjpeg62-turbo-dev \
# 安装 PHP 扩展 libpng-dev \
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ && rm -rf /var/lib/apt/lists/*
&& docker-php-ext-install \
pdo_mysql \ # 安装 PHP 扩展
mbstring \ RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
exif \ && docker-php-ext-install \
pcntl \ pdo_mysql \
bcmath \ mysqli \
gd \ mbstring \
zip \ exif \
sockets pcntl \
bcmath \
# 安装 Redis 扩展 gd \
RUN pecl install redis-5.3.7 && docker-php-ext-enable redis zip \
sockets
# 安装Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # 安装 Redis 扩展
RUN pecl install redis-5.3.7 && docker-php-ext-enable redis
# 验证安装
RUN composer --version # 安装 Xdebug兼容 PHP 7.4 的版本)
RUN pecl install xdebug-3.1.6 && docker-php-ext-enable xdebug
# 设置工作目录
WORKDIR /var/www/html # 安装Composer
COPY --from=composer:2.2.25 /usr/bin/composer /usr/bin/composer
# # 使用Composer安装项目依赖可选根据需要启用, 更多的时候,会出错,要在容器中执行操作)
# RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # 验证安装
# RUN composer install --no-dev --optimize-autoloader --working-dir=/var/www/html RUN composer --version
# # 创建非 root 用户 # 修改 PHP 配置
# RUN useradd -m -u 1000 phpuser && chown -R phpuser:phpuser /var/www/html RUN echo "memory_limit=256M" > /usr/local/etc/php/conf.d/memory-limit.ini \
&& echo "upload_max_filesize=50M" >> /usr/local/etc/php/conf.d/uploads.ini \
# 设置权限, 防止 runtime 目录无法写入的问题 && echo "post_max_size=50M" >> /usr/local/etc/php/conf.d/uploads.ini
# RUN chmod -R 755 /var/www/html
RUN chmod -R 777 /var/www/html/runtime # 创建 Xdebug 配置
RUN echo "zend_extension=xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini
# USER phpuser
# # 使用Composer安装项目依赖可选根据需要启用, 更多的时候,会出错,要在容器中执行操作)
# 暴露端口 # RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
EXPOSE 9000 # RUN composer install --no-dev --optimize-autoloader --working-dir=/var/www/html
# # 创建非 root 用户
# RUN useradd -m -u 1000 phpuser && chown -R phpuser:phpuser /var/www/html
# 设置权限, 防止 runtime 目录无法写入的问题
# RUN chmod -R 755 /var/www/html
# USER phpuser
# 暴露端口
EXPOSE 9000 9003
CMD ["php-fpm"] CMD ["php-fpm"]

View File

@@ -1,7 +1,23 @@
[xdebug] ; Xdebug 配置
xdebug.mode=develop,debug zend_extension=xdebug.so
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal ; 基本配置
xdebug.client_port=9003 xdebug.mode=debug,develop
xdebug.idekey=PHPSTORM xdebug.start_with_request=yes
xdebug.log=/var/log/xdebug.log xdebug.discover_client_host=false
; 远程调试配置
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=VSCODE
; 日志配置(调试时开启)
xdebug.log=/tmp/xdebug.log
xdebug.log_level=7
; 性能分析(可选)
; xdebug.mode=profile
; xdebug.output_dir=/tmp/profiler
; 路径映射(在 VSCode 中配置更灵活)
xdebug.remote_connect_back=0

68
docs/platform/index.md Normal file
View File

@@ -0,0 +1,68 @@
# SASS平台管理
## 网址及密码
- 网址: [https://xcx20.5g-quickapp.com/platform/login/login.html](https://xcx20.5g-quickapp.com/platform/login/login.html)
- 管理员账号: admin
- 密码: admin123456789
**开发模式**
- 前端开发: Layui2+ElementUi
- 后端开发: Thinkphp6 + Php 7.4 + MySQL + Redias
- 开发调试网址[http://localhost/platform/login/login.html](http://localhost/platform/login/login.html)
- 管理员账号: admin
- 密码: admin123456789
## 功能介绍
SASS平台管理系统将会提供了以下主要功能
1. **用户管理**: 管理平台用户的注册、登录及权限分配。
2. **内容管理**: 管理平台上的内容发布、编辑及删除。
3. **数据分析**: 提供平台使用数据的统计与分析功能。
4. **系统设置**: 配置平台的基本设置及参数。
5. **日志管理**: 记录平台操作日志,便于审计和追踪。
6. **通知管理**: 管理平台的通知和消息推送功能。
7. **安全管理**: 提供平台的安全设置和防护措施。
8. **插件管理**: 支持第三方插件的安装和管理,扩展平台功能。
9. **多语言支持**: 支持多种语言,方便不同地区用户使用。
10. **备份与恢复**: 提供数据备份和恢复功能,保障数据安全。
11. **API管理**: 提供API接口的管理和调用方便与其他系统集成。
12. **角色管理**: 定义和分配不同的用户角色及其权限。
13. **审核管理**: 对用户提交的内容进行审核和管理。
14. **报表生成**: 自动生成各类报表,便于数据分析和决策。
15. **通知中心**: 集中管理平台的各类通知和消息。
16. **任务调度**: 支持定时任务的设置和管理,提高平台自动化水平。
17. **多终端支持**: 适配不同终端设备,提升用户体验。
18. **实时监控**: 提供平台运行状态的实时监控和预警功能。
19. **用户反馈**: 收集和管理用户反馈,提升平台服务质量。
20. **版本管理**: 管理平台的版本更新和发布,确保系统稳定运行。
21. **SEO优化**: 提供搜索引擎优化功能,提升平台的可见性。
22. **支付管理**: 集成多种支付方式,方便用户进行交易。
23. **多租户支持**: 支持多租户模式,满足不同客户的需求。
24. **自定义界面**: 支持平台界面的自定义设计,提升品牌形象。
25. **培训与支持**: 提供平台使用的培训资料和技术支持服务。
26. **社区管理**: 支持用户社区的创建和管理,促进用户互动。
27. **日志分析**: 提供日志数据的分析和报表,帮助优化平台性能。
28. **通知模板**: 支持自定义通知模板,提升通知的专业性。
29. **数据导入导出**: 支持平台数据的批量导入和导出,方便数据迁移。
30. **多语言内容管理**: 支持多语言内容的创建和管理,满足全球用户需求。
31. **移动端管理**: 提供移动端的管理功能,方便管理员随时随地操作平台。
32. **用户行为分析**: 通过分析用户行为数据,优化平台功能和用户体验。
33. **自动化营销**: 提供自动化营销工具,提升用户转化率。
34. **内容审核**: 支持自动化和人工内容审核,确保平台内容质量。
35. **系统升级**: 提供便捷的系统升级功能,确保平台始终保持最新状态。
36. **多维权限控制**: 支持复杂的权限控制机制,确保数据安全。
37. **第三方集成**: 支持与第三方服务和工具的集成,扩展平台功能。
38. **用户画像**: 构建用户画像,帮助精准营销和服务。
39. **活动管理**: 支持平台活动的创建和管理,提升用户参与度。
40. **知识库管理**: 提供知识库的创建和管理功能,方便用户获取帮助和支持。
41. **性能优化**: 提供平台性能监测和优化工具,提升系统响应速度。
42. **多渠道支持**: 支持多种渠道的用户接入,提升平台覆盖范围。
43. **自动化测试**: 提供自动化测试工具,确保平台功能的稳定性。
44. **用户分群**: 支持用户分群管理,便于精准营销和服务。
45. **定制化报表**: 支持自定义报表模板,满足不同业务需求。
46. **实时通讯**: 提供实时通讯功能,提升用户互动体验。
47. **内容推荐**: 基于用户行为和偏好,提供个性化内容推荐。

46
docs/shop/index.md Normal file
View File

@@ -0,0 +1,46 @@
# 租户端(tenement)/商户端
欢迎来到租户端(tenement)/商户端的文档页面。在这里,您将找到有关如何使用和管理租户端/商户端的详细信息和指南。
## 目录
- [简介](#简介)
- [登录](#登录)
- [功能概述](#功能概述)
- [常见问题](#常见问题)
- [支持与反馈](#支持与反馈)
## 简介
租户端(tenement)/商户端是一个专为租户/商户设计的平台,旨在简化管理流程,提高运营效率。无论您是制造业企业还是独立商户,我们的系统都能满足您的需求。
## 登录
要开始使用租户端/商户端,您需要按照以下步骤进行登录及配置:
1. 访问登录页面:[登录链接https://example.com/shop/login/login.html](https://example.com/shop/login/login.html)
2. 使用您的管理员账号和密码进行登录。
3. 登录后,您可以根据需要配置系统设置、用户权限和其他功能。
**开发账号**
- 网址[http://localhost/shop/login/login.html](http://localhost/shop/login/login.html)
- 测试账号:防爆电器
- 密码shjs8888
## 功能概述
租户端(tenement)/商户端提供了以下主要功能:
1. **店铺管理**:管理店铺信息、店铺装修、文章管理、文件管理等等内容。
2. **商品管理**: 实时监控和管理商品库存,确保供应链顺畅。
3. **会员管理**: 管理会员信息,提升会员服务质量。
4. **订单管理**: 管理和跟踪客户订单的处理状态。
5. **营销管理**: 创建和管理促销活动,例如优惠券、积分兑换等活动,吸引更多客户。
6. **分销管理**:管理分销商、分销商品、分销订单、分销提现等内容。
7. **财务管理**:管理财务数据,包括收入、支出和利润分析,涉及充值订单、余额明细、积分明细、余额提现等。
8. **数据分析**: 提供详细的数据报表,帮助您了解业务表现和客户行为。(交易分析、会员统计、商品统计)
9. **渠道管理**: 提供微信小程序、快应用、H5等的配置管理
10. **应用管理**:提供应用插件,助力商户运营管理。
11. **系统设置**: 配置系统参数,确保平台运行顺畅。
<!-- 12. **实时监控**: 提供平台运行状态的实时监控和预警功能。 -->

20
src/.env Normal file
View File

@@ -0,0 +1,20 @@
APP_DEBUG = true
APP_TRACE = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[LANG]
default_lang = zh-cn
[DATABASE]
TYPE = mysql
HOSTNAME = newshop_mysql
DATABASE = shop_mallnew
USERNAME = shop_mallnew
PASSWORD = shop_mallnew
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[redis]
HOST = newshop_redis
PORT = 6379
PASSWORD = 'luckyshop123!@#'
EXPIRY = 604800

14
src/.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
/.project
/.vscode
/.settings
/.idea
/.htaccess
/.buildpath
/cert.key
*.log
*.txt
/h5
/web
/mshop
# /config/database.php
/cashregister

View File

@@ -0,0 +1 @@
HUIqMBxOaiPqppGTd9WxmjJwFwX3x-hpbnI1xujpUW4.m7oE98dVL-9XQE2gAJ9VpnsbTfOJ2csnVDIzFqe9osw

26
src/404.html Normal file
View File

@@ -0,0 +1,26 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>404</title>
<style>
body{
background-color:#444;
font-size:14px;
}
h3{
font-size:60px;
color:#eee;
text-align:center;
padding-top:30px;
font-weight:normal;
}
</style>
</head>
<body>
<h3>404您请求的文件不存在!</h3>
</body>
</html>

View File

@@ -0,0 +1,38 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [],
// 自定义页面路径
'link' => [],
// 自定义图标库
'icon_library' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [],
// uni-app 页面,多个逗号隔开
'pages' => [],
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
];

View File

@@ -0,0 +1,30 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
//短信方式
'OssType' => [
'addon\alioss\event\OssType'
],
'Put' => [
'addon\alioss\event\Put'
],
'CloseOss' => [
'addon\alioss\event\CloseOss'
],
'ClearAlbumPic' => [
'addon\alioss\event\ClearAlbumPic'
],
// 展示活动
'ShowPromotion' => [
'addon\alioss\event\ShowPromotion',
],
],
'subscribe' => [
],
];

View File

@@ -0,0 +1,21 @@
<?php
/**
*/
return [
'name' => 'alioss',
'title' => '阿里云OSS',
'description' => '阿里云OSS',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -0,0 +1,18 @@
<?php
// +----------------------------------------------------------------------
// | 平台端菜单设置
// +----------------------------------------------------------------------
return [
[
'name' => 'ALIOSS_CONFIG',
'title' => '阿里云OSS上传配置',
'url' => 'alioss://shop/config/config',
'parent' => 'UPLOAD_OSS',
'is_show' => 0,
'is_control' => 1,
'is_icon' => 0,
'picture' => '',
'picture_select' => '',
'sort' => 1,
],
];

View File

@@ -0,0 +1,39 @@
<?php
/**
*/
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
use addon\alioss\model\Config;
/**
* 删除阿里云图片
*/
class ClearAlbumPic
{
public function handle($params)
{
$config_model = new Config();
$alioss_model = new Alioss();
$config = $config_model->getAliossConfig($params[ 'site_id' ]);
if (!empty($config[ 'data' ])) {
if (!empty($config[ 'data' ][ 'value' ][ 'endpoint' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]) === 0) {
$result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]);
return $result;
}
if (!empty($config[ 'data' ][ 'value' ][ 'domain' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]) === 0) {
$result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]);
return $result;
}
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
*/
namespace addon\alioss\event;
use addon\alioss\model\Config;
/**
* 关闭云上传
*/
class CloseOss
{
public function handle()
{
$config_model = new Config();
$result = $config_model->modifyConfigIsUse(0);
return $result;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 云上传方式
*/
class OssType
{
/**
* 短信发送方式方式及配置
*/
public function handle()
{
$info = array(
"sms_type" => "alioss",
"sms_type_name" => "阿里云上传",
"edit_url" => "alioss://shop/config/config",
"shop_url" => "alioss://shop/config/config",
"desc" => "阿里云上传"
);
return $info;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
*/
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
/**
* 云上传方式
*/
class Put
{
/**
* @param $param
* @return array
*/
public function handle($param)
{
$qiniu_model = new Alioss();
$result = $qiniu_model->putFile($param);
return $result;
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @param array $params
* @return array
*/
public function handle($params = [])
{
$data = [
'admin' => [
],
'shop' => [
[
//插件名称
'name' => 'alioss',
//展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具)
'show_type' => 'tool',
//展示主题
'title' => '阿里云OSS',
//展示介绍
'description' => '阿里云OSS配置',
//展示图标
'icon' => 'addon/alioss/icon.png',
//跳转链接
'url' => 'alioss://shop/config/config',
],
],
];
return $data;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

BIN
src/addon/alioss/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -0,0 +1,146 @@
<?php
/**
*/
namespace addon\alioss\model;
use app\model\BaseModel;
use OSS\Core\OssException;
use OSS\OssClient;
use think\facade\Log;
/**
* 阿里云OSS上传
*/
class Alioss extends BaseModel
{
/**
* 字节组上传
* @param $data
* @param $key
* @return array
*/
public function put($param)
{
$data = $param['data'];
$key = $param['key'];
$config_model = new Config();
$config_result = $config_model->getAliossConfig();
$config = $config_result['data'];
if ($config['is_use'] == 1) {
$config = $config['value'];
$access_key_id = $config['access_key_id'];
$access_key_secret = $config['access_key_secret'];
$bucket = $config['bucket'];
$endpoint = $config['endpoint'];
try {
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
$result = $ossClient->putObject($bucket, $key, $data);
$is_domain = $config[ 'is_domain' ] ?? 0;
$path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
$data = array (
'path' => $path,
// "path" => $result["info"]["url"],
'domain' => $endpoint,
'bucket' => $bucket
);
return $this->success($data);
} catch (OssException $e) {
return $this->error('', $e->getErrorMessage());
}
}
}
/**
* 设置阿里云OSS参数配置
* @param unknown $filePath 上传图片路径
* @param unknown $key 上传到阿里云后保存的文件名
*/
public function putFile($param)
{
$file_path = $param['file_path'];
$key = $param['key'];
$config_model = new Config();
$config = $config_model->getAliossConfig()['data'];
if ($config['is_use'] == 1) {
$config = $config['value'];
$access_key_id = $config['access_key_id'];
$access_key_secret = $config['access_key_secret'];
$bucket = $config['bucket'];
//要上传的空间
$endpoint = $config['endpoint'];
try {
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
$result = $ossClient->uploadFile($bucket, $key, $file_path);
$is_domain = $config[ 'is_domain' ] ?? 0;
$path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
$path = str_replace('http://', 'https://', $path);
//返回图片的完整URL
$data = array (
// "path" => $this->subEndpoint($endpoint, $bucket)."/". $key,
'path' => $path,
'domain' => $endpoint,
'bucket' => $bucket
);
return $this->success($data);
} catch (\Exception $e) {
return $this->error('', $e->getMessage());
}
}
}
public function subEndpoint($endpoint, $bucket)
{
if (strpos($endpoint, 'http://') === 0) {
$temp = 'http://';
} else {
$temp = 'https://';
}
$temp_array = explode($temp, $endpoint);
return $temp . $bucket . '.' . $temp_array[ 1 ];
}
/**
* @param $file_path
* @return array
* 删除阿里云图片
*/
public function deleteAlbumPic($file_path, $prefix)
{
$config_model = new Config();
$config_result = $config_model->getAliossConfig();
$config = $config_result['data'];
if (!empty($config)) {
$config = $config['value'];
$access_key_id = $config['access_key_id'];
$access_key_secret = $config['access_key_secret'];
$bucket = $config['bucket'];
//要上传的空间
$endpoint = $config['endpoint'];
try {
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
$ossClient->deleteObject($bucket, str_replace($prefix . '/', '', $file_path));
$ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'big')));
$ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'mid')));
$ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'small')));
return $this->success();
} catch (OssException $e) {
return $this->error('', $e->getErrorMessage());
}
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
*/
namespace addon\alioss\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 阿里云配置
*/
class Config extends BaseModel
{
/**
* 设置阿里云OSS上传配置
* array $data
*/
public function setAliossConfig($data, $status, $site_id = 1, $app_module = 'shop')
{
if ($status == 1) {
event('CloseOss', []);//同步关闭所有云上传
}
$config = new ConfigModel();
$res = $config->setConfig($data, '阿里云OSS上传配置', $status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
return $res;
}
/**
* 获取阿里云上传配置
*/
public function getAliossConfig($site_id = 1, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
return $res;
}
/**
* 配置阿里云开关状态
* @param $status
*/
public function modifyConfigIsUse($status, $site_id = 1, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->modifyConfigIsUse($status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
return $res;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
*/
namespace addon\alioss\shop\controller;
use addon\alioss\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
/**
* 七牛云上传管理
*/
class Config extends BaseShop
{
/**
* 云上传配置
* @return mixed
*/
public function config()
{
$config_model = new ConfigModel();
if (request()->isJson()) {
$bucket = input('bucket', '');
$access_key_id = input('access_key_id', '');
$access_key_secret = input('access_key_secret', '');
$endpoint = input('endpoint', '');
$status = input('status', 0);
$domain = input('domain', '');
$is_domain = input('is_domain', 0);
$data = array (
'bucket' => $bucket,
'access_key_id' => $access_key_id,
'access_key_secret' => $access_key_secret,
'endpoint' => $endpoint,
'domain' => $domain,
'is_domain' => $is_domain
);
$result = $config_model->setAliossConfig($data, $status, $this->site_id, $this->app_module);
return $result;
} else {
$info_result = $config_model->getAliossConfig($this->site_id, $this->app_module);
$info = $info_result['data'];
$this->assign('info', $info);
return $this->fetch('config/config');
}
}
}

View File

@@ -0,0 +1,120 @@
<div class="layui-form form-wrap">
<div class="layui-form-item">
<label class="layui-form-label">是否开启:</label>
<div class="layui-input-block" id="isOpen">
<input type="checkbox" name="status" lay-filter="isOpen" value="1" lay-skin="switch" {if condition="$info.is_use == 1"} checked {/if} />
</div>
<div class="word-aux">当前使用阿里云上传配置</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="required">*</span>AccessKeyID</label>
<div class="layui-input-block">
<input type="text" name="access_key_id" lay-verify="required" placeholder="请输入Access Key ID" value="{$info.value.access_key_id ?? ''}" autocomplete="off" class="layui-input len-long">
</div>
<div class="word-aux">填写阿里云Access Key管理的(ID)。</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="required">*</span>AccessKeySecret</label>
<div class="layui-input-block">
<input type="text" name="access_key_secret" lay-verify="required" placeholder="请输入Access Key Secret" value="{$info.value.access_key_secret ?? ''}" autocomplete="off" class="layui-input len-long">
</div>
<div class="word-aux">Access Key Secret是您访问阿里云API的密钥具有该账户完全的权限请您妥善保管。(填写完Access Key ID 和 Access Key Secret 后请选择bucket)</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="required">*</span>Bucket</label>
<div class="layui-input-block">
<input type="text" name="bucket" lay-verify="required" placeholder="请输入存储空间的名称" value="{$info.value.bucket ?? ''}" autocomplete="off" class="layui-input len-long">
</div>
<div class="word-aux">与阿里云OSS开通对象名称一致</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="required">*</span>endpoint</label>
<div class="layui-input-block">
<input type="text" name="endpoint" lay-verify="required" placeholder="请输入endpoint" value="{$info.value.endpoint ?? ''}" autocomplete="off" class="layui-input len-long">
</div>
<div class="word-aux">Bucket地域endpoint</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否开启自定义域名:</label>
<div class="layui-input-block" >
<input type="checkbox" name="is_domain" lay-filter="is_domain" value="1" lay-skin="switch" {if condition="!empty($info.value.is_domain) && $info.value.is_domain == 1"} checked {/if} />
</div>
<div class="word-aux">默认选关闭官方建议开启绑定域名域名格式http://xx.xxxx.com/(不可绑定当前网站域名,建议新开二级域名)</div>
</div>
<div class="layui-form-item domain-view" {if empty($info.value.is_domain) || $info.value.is_domain == 0}style="display:none;"{/if}>
<label class="layui-form-label"><span class="required">*</span>domain</label>
<div class="layui-input-block">
<input type="text" name="domain" lay-verify="domain" placeholder="请输入domain" value="{$info.value.domain ?? ''}" autocomplete="off" class="layui-input len-long">
</div>
<div class="word-aux">域名格式http://xx.xxxx.com/(不可绑定当前网站域名,建议新开二级域名)</div>
</div>
<div class="form-row">
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
</div>
</div>
<script>
layui.use('form', function() {
var form = layui.form,
repeat_flag = false; //防重复标识
form.on('switch(is_domain)', function(data){
if(data.elem.checked){
$(".domain-view").show();
}else{
$(".domain-view").hide();
}
});
form.verify({
domain: function (value, item) {
var is_domain = $("input[name=is_domain]").prop("checked");
if(is_domain > 0 && value == ""){
return '自定义域名不可为空!';
}
},
});
form.on('submit(save)', function(data) {
if (repeat_flag) return;
repeat_flag = true;
$.ajax({
url: ns.url("alioss://shop/config/config"),
data: data.field,
dataType: 'JSON',
type: 'POST',
success: function(res) {
repeat_flag = false;
if (res.code >= 0) {
layer.confirm('编辑成功', {
title:'操作提示',
btn: ['返回列表', '继续编辑'],
yes: function(index, layero) {
location.hash = ns.hash("shop/upload/oss");
layer.close(index);
},
btn2: function(index, layero) {
layer.close(index);
}
});
}else{
layer.msg(res.message);
}
}
});
});
form.render();
});
function back() {
location.hash = ns.hash("shop/upload/oss");
}
</script>

View File

@@ -0,0 +1,38 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [],
// 自定义页面路径
'link' => [],
// 自定义图标库
'icon_library' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [],
// uni-app 页面,多个逗号隔开
'pages' => [],
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
];

View File

@@ -0,0 +1,50 @@
<?php
/**
*/
return [
'bind' => [
],
'listen' => [
//支付异步回调
'PayNotify' => [
'addon\alipay\event\PayNotify'
],
//支付方式,后台查询
'PayType' => [
'addon\alipay\event\PayType'
],
//支付,前台应用
'Pay' => [
'addon\alipay\event\Pay'
],
'PayClose' => [
'addon\alipay\event\PayClose'
],
'PayRefund' => [
'addon\alipay\event\PayRefund'
],
'PayTransfer' => [
'addon\alipay\event\PayTransfer'
],
'TransferType' => [
'addon\alipay\event\TransferType'
],
'AuthcodePay' => [
'addon\alipay\event\AuthcodePay'
],
'PayOrderQuery' => [
'addon\alipay\event\PayOrderQuery'
],
],
'subscribe' => [
],
];

View File

@@ -0,0 +1,21 @@
<?php
/**
*/
return [
'name' => 'alipay',
'title' => '支付宝支付',
'description' => '支付宝支付功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -0,0 +1,23 @@
<?php
/**
*/
return [
[
'name' => 'ALI_PAY_CONFIG',
'title' => '支付宝支付编辑',
'url' => 'alipay://shop/pay/config',
'parent' => 'CONFIG_PAY',
'is_show' => 0,
'is_control' => 1,
'is_icon' => 0,
'picture' => '',
'picture_select' => '',
'sort' => 1,
],
];

View File

@@ -0,0 +1,231 @@
<?php
/**
* 多媒体文件客户端
* @author yikai.hu
* @version $Id: AlipayMobilePublicMultiMediaClient.php, v 0.1 Aug 15, 2014 10:19:01 AM yikai.hu Exp $
*/
//namespace alipay\api ;
include("AlipayMobilePublicMultiMediaExecute.php");
class AlipayMobilePublicMultiMediaClient{
private $DEFAULT_CHARSET = 'UTF-8';
private $METHOD_POST = "POST";
private $METHOD_GET = "GET";
private $SIGN = 'sign'; //get name
private $timeout = 10 ;// 超时时间
private $serverUrl;
private $appId;
private $privateKey;
private $prodCode;
private $format = 'json'; //todo
private $sign_type = 'RSA'; //todo
private $charset;
private $apiVersion = "1.0";
private $apiMethodName = "alipay.mobile.public.multimedia.download";
private $media_id = "L21pZnMvVDFQV3hYWGJKWFhYYUNucHJYP3Q9YW13ZiZ4c2lnPTU0MzRhYjg1ZTZjNWJmZTMxZGJiNjIzNDdjMzFkNzkw575";
//此处写死的,实际开发中,请传入
private $connectTimeout = 3000;
private $readTimeout = 15000;
function __construct($serverUrl = '', $appId = '', $partner_private_key = '', $format = '', $charset = 'GBK'){
$this -> serverUrl = $serverUrl;
$this -> appId = $appId;
$this -> privateKey = $partner_private_key;
$this -> format = $format;
$this -> charset = $charset;
}
/**
* getContents 获取网址内容
* @param $request
* @return text | bin
*/
public function getContents(){
//自己的服务器如果没有 curl可用fsockopen() 等
//1:
//2 私钥格式
$datas = array(
"app_id" => $this -> appId,
"method" => $this -> METHOD_POST,
"sign_type" => $this -> sign_type,
"version" => $this -> apiVersion,
"timestamp" => date('Y-m-d H:i:s') ,//yyyy-MM-dd HH:mm:ss
"biz_content" => '{"mediaId":"'. $this -> media_id .'"}',
"charset" => $this -> charset
);
//要提交的数据
$data_sign = $this -> buildGetUrl( $datas );
$post_data = $data_sign;
//初始化 curl
$ch = curl_init();
//设置目标服务器
curl_setopt($ch, CURLOPT_URL, $this -> serverUrl );
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//超时时间
curl_setopt($ch, CURLOPT_TIMEOUT, $this-> timeout);
if( $this-> METHOD_POST == 'POST'){
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $output;
//分离头部
//list($header, $body) = explode("\r\n\r\n", $output, 2);
$datas = explode("\r\n\r\n", $output, 2);
$header = $datas[0];
if( $httpCode == '200'){
$body = $datas[1];
}else{
$body = '';
}
return $this -> execute( $header, $body, $httpCode );
}
/**
*
* @param $request
* @return text | bin
*/
public function execute( $header = '', $body = '', $httpCode = '' ){
$exe = new AlipayMobilePublicMultiMediaExecute( $header, $body, $httpCode );
return $exe;
}
public function buildGetUrl( $query = array() ){
if( ! is_array( $query ) ){
//exit;
}
//排序参数,
$data = $this -> buildQuery( $query );
// 私钥密码
$passphrase = '';
$key_width = 64;
//私钥
$privateKey = $this -> privateKey;
$p_key = array();
//如果私钥是 1行
if( ! stripos( $privateKey, "\n" ) ){
$i = 0;
while( $key_str = substr( $privateKey , $i * $key_width , $key_width) ){
$p_key[] = $key_str;
$i ++ ;
}
}else{
//echo '一行?';
}
$privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" . implode("\n", $p_key) ;
$privateKey = $privateKey ."\n-----END RSA PRIVATE KEY-----";
// echo "\n\n私钥:\n";
// echo( $privateKey );
// echo "\n\n\n";
//私钥
$private_id = openssl_pkey_get_private( $privateKey , $passphrase);
// 签名
$signature = '';
if("RSA2"==$this->sign_type){
openssl_sign($data, $signature, $private_id, OPENSSL_ALGO_SHA256 );
}else{
openssl_sign($data, $signature, $private_id, OPENSSL_ALGO_SHA1 );
}
openssl_free_key( $private_id );
//加密后的内容通常含有特殊字符,需要编码转换下
$signature = base64_encode($signature);
$signature = urlencode( $signature );
//$signature = 'XjUN6YM1Mc9HXebKMv7GTLy7gmyhktyOgKk2/Jf+cz4DtP6udkzTdpkjW2j/Z4ZSD7xD6CNYI1Spz4yS93HPT0a5X9LgFWYY8SaADqe+ArXg+FBSiTwUz49SE//Xd9+LEiIRsSFkbpkuiGoO6mqJmB7vXjlD5lx6qCM3nb41wb8=';
$out = $data .'&'. $this -> SIGN .'='. $signature;
// echo "\n\n 加密后:\n";
// echo( $out );
// echo "\n\n\n";
return $out ;
}
/*
* 查询参数排序 a-z
* */
public function buildQuery( $query ){
if ( !$query ) {
return null;
}
//将要 参数 排序
ksort( $query );
//重新组装参数
$params = array();
foreach($query as $key => $value){
$params[] = $key .'='. $value ;
}
$data = implode('&', $params);
return $data;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* 多媒体文件客户端
* @author yuanwai.wang
* @version $Id: AlipayMobilePublicMultiMediaExecute.php, v 0.1 Aug 15, 2014 10:19:01 AM yuanwai.wang Exp $
*/
//namespace alipay\api ;
class AlipayMobilePublicMultiMediaExecute{
private $code = 200 ;
private $msg = '';
private $body = '';
private $params = '';
private $fileSuffix = array(
"image/jpeg" => 'jpg', //+
"text/plain" => 'text'
);
/*
* @$header : 头部
* */
function __construct( $header, $body, $httpCode ){
$this -> code = $httpCode;
$this -> msg = '';
$this -> params = $header ;
$this -> body = $body;
}
/**
*
* @return text | bin
*/
public function getCode(){
return $this -> code ;
}
/**
*
* @return text | bin
*/
public function getMsg(){
return $this -> msg ;
}
/**
*
* @return text | bin
*/
public function getType(){
$subject = $this -> params ;
$pattern = '/Content\-Type:([^;]+)/';
preg_match($pattern, $subject, $matches);
if( $matches ){
$type = $matches[1];
}else{
$type = 'application/download';
}
return str_replace( ' ', '', $type );
}
/**
*
* @return text | bin
*/
public function getContentLength(){
$subject = $this -> params ;
$pattern = '/Content-Length:\s*([^\n]+)/';
preg_match($pattern, $subject, $matches);
return (int)( isset($matches[1] ) ? $matches[1] : '' );
}
public function getFileSuffix( $fileType ){
$type = isset( $this -> fileSuffix[ $fileType ] ) ? $this -> fileSuffix[ $fileType ] : 'text/plain' ;
if( !$type ){
$type = 'json';
}
return $type;
}
/**
*
* @return text | bin
*/
public function getBody(){
//header('Content-type: image/jpeg');
return $this -> body ;
}
/**
* 获取参数
* @return text | bin
*/
public function getParams(){
return $this -> params ;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,527 @@
<?php
/**
* 验证支付宝公钥证书是否可信
* @param $alipayCert 支付宝公钥证书
* @param $rootCert 支付宝根证书
*/
function isTrusted($alipayCert, $rootCert)
{
$alipayCerts = readPemCertChain($alipayCert);
$rootCerts = readPemCertChain($rootCert);
if (verifyCertChain($alipayCerts, $rootCerts)) {
return verifySignature($alipayCert, $rootCert);
} else {
return false;
}
}
function verifySignature($alipayCert, $rootCert)
{
$alipayCertArray = explode("-----END CERTIFICATE-----", $alipayCert);
$rootCertArray = explode("-----END CERTIFICATE-----", $rootCert);
$length = count($rootCertArray) - 1;
$checkSign = isCertSigner($alipayCertArray[0] . "-----END CERTIFICATE-----", $alipayCertArray[1] . "-----END CERTIFICATE-----");
if (!$checkSign) {
$checkSign = isCertSigner($alipayCertArray[1] . "-----END CERTIFICATE-----", $alipayCertArray[0] . "-----END CERTIFICATE-----");
if ($checkSign) {
$issuer = openssl_x509_parse($alipayCertArray[0] . "-----END CERTIFICATE-----")['issuer'];
for ($i = 0; $i < $length; $i++) {
$subject = openssl_x509_parse($rootCertArray[$i] . "-----END CERTIFICATE-----")['subject'];
if ($issuer == $subject) {
isCertSigner($alipayCertArray[0] . "-----END CERTIFICATE-----", $rootCertArray[$i] . $rootCertArray);
return $checkSign;
}
}
} else {
return $checkSign;
}
} else {
$issuer = openssl_x509_parse($alipayCertArray[1] . "-----END CERTIFICATE-----")['issuer'];
for ($i = 0; $i < $length; $i++) {
$subject = openssl_x509_parse($rootCertArray[$i] . "-----END CERTIFICATE-----")['subject'];
if ($issuer == $subject) {
$checkSign = isCertSigner($alipayCertArray[1] . "-----END CERTIFICATE-----", $rootCertArray[$i] . "-----END CERTIFICATE-----");
return $checkSign;
}
}
return $checkSign;
}
}
function readPemCertChain($cert)
{
$array = explode("-----END CERTIFICATE-----", $cert);
$certs[] = null;
for ($i = 0; $i < count($array) - 1; $i++) {
$certs[$i] = openssl_x509_parse($array[$i] . "-----END CERTIFICATE-----");
}
return $certs;
}
function verifyCert($prev, $rootCerts)
{
$nowTime = time();
if ($nowTime < $prev['validFrom_time_t']) {
echo "证书未激活";
return false;
}
if ($nowTime > $prev['validTo_time_t']) {
echo "证书已经过期";
return false;
}
$subjectMap = null;
for ($i = 0; $i < count($rootCerts); $i++) {
$subjectDN = array2string($rootCerts[$i]['subject']);
$subjectMap[$subjectDN] = $rootCerts[$i];
}
$issuerDN = array2string(($prev['issuer']));
if (!array_key_exists($issuerDN, $subjectMap)) {
echo "证书链验证失败";
return false;
}
return true;
}
/**
* 验证证书链是否是信任证书库中证书签发的
* @param $alipayCerts 目标验证证书列表
* @param $rootCerts 可信根证书列表
*/
function verifyCertChain($alipayCerts, $rootCerts)
{
$sorted = sortByDn($alipayCerts);
if (!$sorted) {
echo "证书链验证失败:不是完整的证书链";
return false;
}
//先验证第一个证书是不是信任库中证书签发的
$prev = $alipayCerts[0];
$firstOK = verifyCert($prev, $rootCerts);
$length = count($alipayCerts);
if (!$firstOK || $length == 1) {
return $firstOK;
}
$nowTime = time();
//验证证书链
for ($i = 1; $i < $length; $i++) {
$cert = $alipayCerts[$i];
if ($nowTime < $cert['validFrom_time_t']) {
echo "证书未激活";
return false;
}
if ($nowTime > $cert['validTo_time_t']) {
echo "证书已经过期";
return false;
}
}
return true;
}
/**
* 将证书链按照完整的签发顺序进行排序,排序后证书链为:[issuerA, subjectA]-[issuerA, subjectB]-[issuerB, subjectC]-[issuerC, subjectD]...
* @param $certs 证书链
*/
function sortByDn(&$certs)
{
//是否包含自签名证书
$hasSelfSignedCert = false;
$subjectMap = null;
$issuerMap = null;
for ($i = 0; $i < count($certs); $i++) {
if (isSelfSigned($certs[$i])) {
if ($hasSelfSignedCert) {
return false;
}
$hasSelfSignedCert = true;
}
$subjectDN = array2string($certs[$i]['subject']);
$issuerDN = array2string(($certs[$i]['issuer']));
$subjectMap[$subjectDN] = $certs[$i];
$issuerMap[$issuerDN] = $certs[$i];
}
$certChain = null;
addressingUp($subjectMap, $certChain, $certs[0]);
addressingDown($issuerMap, $certChain, $certs[0]);
//说明证书链不完整
if (count($certs) != count($certChain)) {
return false;
}
//将证书链复制到原先的数据
for ($i = 0; $i < count($certs); $i++) {
$certs[$i] = $certChain[count($certs) - $i - 1];
}
return true;
}
/**
* 验证证书是否是自签发的
* @param $cert 目标证书
*/
function isSelfSigned($cert)
{
$subjectDN = array2string($cert['subject']);
$issuerDN = array2string($cert['issuer']);
return ($subjectDN == $issuerDN);
}
function array2string($array)
{
$string = [];
if ($array && is_array($array)) {
foreach ($array as $key => $value) {
$string[] = $key . '=' . $value;
}
}
return implode(',', $string);
}
/**
* 向上构造证书链
* @param $subjectMap 主题和证书的映射
* @param $certChain 证书链
* @param $current 当前需要插入证书链的证书include
*/
function addressingUp($subjectMap, &$certChain, $current)
{
$certChain[] = $current;
if (isSelfSigned($current)) {
return;
}
$issuerDN = array2string($current['issuer']);
if (!array_key_exists($issuerDN, $subjectMap)) {
return;
}
addressingUp($subjectMap, $certChain, $subjectMap[$issuerDN]);
}
/**
* 向下构造证书链
* @param $issuerMap 签发者和证书的映射
* @param $certChain 证书链
* @param $current 当前需要插入证书链的证书exclude
*/
function addressingDown($issuerMap, &$certChain, $current)
{
$subjectDN = array2string($current['subject']);
if (!array_key_exists($subjectDN, $issuerMap)) {
return $certChain;
}
$certChain[] = $issuerMap[$subjectDN];
addressingDown($issuerMap, $certChain, $issuerMap[$subjectDN]);
}
/**
* Extract signature from der encoded cert.
* Expects x509 der encoded certificate consisting of a section container
* containing 2 sections and a bitstream. The bitstream contains the
* original encrypted signature, encrypted by the public key of the issuing
* signer.
* @param string $der
* @return string on success
* @return bool false on failures
*/
function extractSignature($der = false)
{
if (strlen($der) < 5) {
return false;
}
// skip container sequence
$der = substr($der, 4);
// now burn through two sequences and the return the final bitstream
while (strlen($der) > 1) {
$class = ord($der[0]);
$classHex = dechex($class);
switch ($class) {
// BITSTREAM
case 0x03:
$len = ord($der[1]);
$bytes = 0;
if ($len & 0x80) {
$bytes = $len & 0x0f;
$len = 0;
for ($i = 0; $i < $bytes; $i++) {
$len = ($len << 8) | ord($der[$i + 2]);
}
}
return substr($der, 3 + $bytes, $len);
break;
// SEQUENCE
case 0x30:
$len = ord($der[1]);
$bytes = 0;
if ($len & 0x80) {
$bytes = $len & 0x0f;
$len = 0;
for ($i = 0; $i < $bytes; $i++) {
$len = ($len << 8) | ord($der[$i + 2]);
}
}
$contents = substr($der, 2 + $bytes, $len);
$der = substr($der, 2 + $bytes + $len);
break;
default:
return false;
break;
}
}
return false;
}
/**
* Get signature algorithm oid from der encoded signature data.
* Expects decrypted signature data from a certificate in der format.
* This ASN1 data should contain the following structure:
* SEQUENCE
* SEQUENCE
* OID (signature algorithm)
* NULL
* OCTET STRING (signature hash)
* @return bool false on failures
* @return string oid
*/
function getSignatureAlgorithmOid($der = null)
{
// Validate this is the der we need...
if (!is_string($der) or strlen($der) < 5) {
return false;
}
$bit_seq1 = 0;
$bit_seq2 = 2;
$bit_oid = 4;
if (ord($der[$bit_seq1]) !== 0x30) {
die('Invalid DER passed to getSignatureAlgorithmOid()');
}
if (ord($der[$bit_seq2]) !== 0x30) {
die('Invalid DER passed to getSignatureAlgorithmOid()');
}
if (ord($der[$bit_oid]) !== 0x06) {
die('Invalid DER passed to getSignatureAlgorithmOid');
}
// strip out what we don't need and get the oid
$der = substr($der, $bit_oid);
// Get the oid
$len = ord($der[1]);
$bytes = 0;
if ($len & 0x80) {
$bytes = $len & 0x0f;
$len = 0;
for ($i = 0; $i < $bytes; $i++) {
$len = ($len << 8) | ord($der[$i + 2]);
}
}
$oid_data = substr($der, 2 + $bytes, $len);
// Unpack the OID
$oid = floor(ord($oid_data[0]) / 40);
$oid .= '.' . ord($oid_data[0]) % 40;
$value = 0;
$i = 1;
while ($i < strlen($oid_data)) {
$value = $value << 7;
$value = $value | (ord($oid_data[$i]) & 0x7f);
if (!(ord($oid_data[$i]) & 0x80)) {
$oid .= '.' . $value;
$value = 0;
}
$i++;
}
return $oid;
}
/**
* Get signature hash from der encoded signature data.
* Expects decrypted signature data from a certificate in der format.
* This ASN1 data should contain the following structure:
* SEQUENCE
* SEQUENCE
* OID (signature algorithm)
* NULL
* OCTET STRING (signature hash)
* @return bool false on failures
* @return string hash
*/
function getSignatureHash($der = null)
{
// Validate this is the der we need...
if (!is_string($der) or strlen($der) < 5) {
return false;
}
if (ord($der[0]) !== 0x30) {
die('Invalid DER passed to getSignatureHash()');
}
// strip out the container sequence
$der = substr($der, 2);
if (ord($der[0]) !== 0x30) {
die('Invalid DER passed to getSignatureHash()');
}
// Get the length of the first sequence so we can strip it out.
$len = ord($der[1]);
$bytes = 0;
if ($len & 0x80) {
$bytes = $len & 0x0f;
$len = 0;
for ($i = 0; $i < $bytes; $i++) {
$len = ($len << 8) | ord($der[$i + 2]);
}
}
$der = substr($der, 2 + $bytes + $len);
// Now we should have an octet string
if (ord($der[0]) !== 0x04) {
die('Invalid DER passed to getSignatureHash()');
}
$len = ord($der[1]);
$bytes = 0;
if ($len & 0x80) {
$bytes = $len & 0x0f;
$len = 0;
for ($i = 0; $i < $bytes; $i++) {
$len = ($len << 8) | ord($der[$i + 2]);
}
}
return bin2hex(substr($der, 2 + $bytes, $len));
}
/**
* Determine if one cert was used to sign another
* Note that more than one CA cert can give a positive result, some certs
* re-issue signing certs after having only changed the expiration dates.
* @param string $cert - PEM encoded cert
* @param string $caCert - PEM encoded cert that possibly signed $cert
* @return bool
*/
function isCertSigner($certPem = null, $caCertPem = null)
{
if (!function_exists('openssl_pkey_get_public')) {
die('Need the openssl_pkey_get_public() function.');
}
if (!function_exists('openssl_public_decrypt')) {
die('Need the openssl_public_decrypt() function.');
}
if (!function_exists('hash')) {
die('Need the php hash() function.');
}
if (empty($certPem) or empty($caCertPem)) {
return false;
}
// Convert the cert to der for feeding to extractSignature.
$certDer = pemToDer($certPem);
if (!is_string($certDer)) {
die('invalid certPem');
}
// Grab the encrypted signature from the der encoded cert.
$encryptedSig = extractSignature($certDer);
if (!is_string($encryptedSig)) {
die('Failed to extract encrypted signature from certPem.');
}
// Extract the public key from the ca cert, which is what has
// been used to encrypt the signature in the cert.
$pubKey = openssl_pkey_get_public($caCertPem);
if ($pubKey === false) {
die('Failed to extract the public key from the ca cert.');
}
// Attempt to decrypt the encrypted signature using the CA's public
// key, returning the decrypted signature in $decryptedSig. If
// it can't be decrypted, this ca was not used to sign it for sure...
$rc = openssl_public_decrypt($encryptedSig, $decryptedSig, $pubKey);
if ($rc === false) {
return false;
}
// We now have the decrypted signature, which is der encoded
// asn1 data containing the signature algorithm and signature hash.
// Now we need what was originally hashed by the issuer, which is
// the original DER encoded certificate without the issuer and
// signature information.
$origCert = stripSignerAsn($certDer);
if ($origCert === false) {
die('Failed to extract unsigned cert.');
}
// Get the oid of the signature hash algorithm, which is required
// to generate our own hash of the original cert. This hash is
// what will be compared to the issuers hash.
$oid = getSignatureAlgorithmOid($decryptedSig);
if ($oid === false) {
die('Failed to determine the signature algorithm.');
}
switch ($oid) {
case '1.2.840.113549.2.2':
$algo = 'md2';
break;
case '1.2.840.113549.2.4':
$algo = 'md4';
break;
case '1.2.840.113549.2.5':
$algo = 'md5';
break;
case '1.3.14.3.2.18':
$algo = 'sha';
break;
case '1.3.14.3.2.26':
$algo = 'sha1';
break;
case '2.16.840.1.101.3.4.2.1':
$algo = 'sha256';
break;
case '2.16.840.1.101.3.4.2.2':
$algo = 'sha384';
break;
case '2.16.840.1.101.3.4.2.3':
$algo = 'sha512';
break;
default:
die('Unknown signature hash algorithm oid: ' . $oid);
break;
}
// Get the issuer generated hash from the decrypted signature.
$decryptedHash = getSignatureHash($decryptedSig);
// Ok, hash the original unsigned cert with the same algorithm
// and if it matches $decryptedHash we have a winner.
$certHash = hash($algo, $origCert);
return ($decryptedHash === $certHash);
}
/**
* Convert pem encoded certificate to DER encoding
* @return string $derEncoded on success
* @return bool false on failures
*/
function pemToDer($pem = null)
{
if (!is_string($pem)) {
return false;
}
$cert_split = preg_split('/(-----((BEGIN)|(END)) CERTIFICATE-----)/', $pem);
if (!isset($cert_split[1])) {
return false;
}
return base64_decode($cert_split[1]);
}
/**
* Obtain der cert with issuer and signature sections stripped.
* @param string $der - der encoded certificate
* @return string $der on success
* @return bool false on failures.
*/
function stripSignerAsn($der = null)
{
if (!is_string($der) or strlen($der) < 8) {
return false;
}
$bit = 4;
$len = ord($der[($bit + 1)]);
$bytes = 0;
if ($len & 0x80) {
$bytes = $len & 0x0f;
$len = 0;
for ($i = 0; $i < $bytes; $i++) {
$len = ($len << 8) | ord($der[$bit + $i + 2]);
}
}
return substr($der, 4, $len + 4);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,71 @@
<?php
/**
* 加密工具类
*
* User: jiehua
* Date: 16/3/30
* Time: 下午3:25
*/
/**
* 加密方法
* @param string $str
* @return string
*/
function new_encrypt($str,$screct_key){
//AES, 128 模式加密数据 CBC
$screct_key = base64_decode($screct_key);
$str = trim($str);
$str = addPKCS7Padding($str);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1);
$encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC);
return base64_encode($encrypt_str);
}
/**
* 解密方法
* @param string $str
* @return string
*/
function new_decrypt($str,$screct_key){
//AES, 128 模式加密数据 CBC
$str = base64_decode($str);
$screct_key = base64_decode($screct_key);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1);
$encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC);
$encrypt_str = trim($encrypt_str);
$encrypt_str = stripPKSC7Padding($encrypt_str);
return $encrypt_str;
}
/**
* 填充算法
* @param string $source
* @return string
*/
function addPKCS7Padding($source){
$source = trim($source);
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - (strlen($source) % $block);
if ($pad <= $block) {
$char = chr($pad);
$source .= str_repeat($char, $pad);
}
return $source;
}
/**
* 移去填充算法
* @param string $source
* @return string
*/
function stripPKSC7Padding($source){
$source = trim($source);
$char = substr($source, -1);
$num = ord($char);
if($num==62)return $source;
$source = substr($source,0,-$num);
return $source;
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* TODO 补充说明
*
* User: jiehua
* Date: 16/3/30
* Time: 下午8:55
*/
class EncryptParseItem {
public $startIndex;
public $endIndex;
public $encryptContent;
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* TODO 补充说明
*
* User: jiehua
* Date: 16/3/30
* Time: 下午8:51
*/
class EncryptResponseData {
public $realContent;
public $returnContent;
}

View File

@@ -0,0 +1,17 @@
<?php
namespace addon\alipay\data\sdk;
/**
* Created by PhpStorm.
* User: jiehua
* Date: 15/5/2
* Time: 下午6:21
*/
class SignData {
public $signSourceData=null;
public $sign=null;
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.fund.trans.toaccount.transfer request
*
* @author auto create
* @since 1.0, 2018-08-14 14:05:00
*/
class AlipayFundTransToaccountTransferRequest
{
/**
* 单笔转账到支付宝账户接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.fund.trans.toaccount.transfer";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.fund.trans.uni.transfer request
*
* @author auto create
* @since 1.0, 2020-04-02 22:40:08
*/
class AlipayFundTransUniTransferRequest
{
/**
* 支付宝转账支付接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.fund.trans.uni.transfer";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.app.pay request
*
* @author auto create
* @since 1.0, 2018-07-16 16:20:00
*/
class AlipayTradeAppPayRequest
{
/**
* app支付接口2.0
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.app.pay";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* ALIPAY API: alipay.trade.cancel request
*
* @author auto create
* @since 1.0, 2018-07-13 17:18:06
*/
class AlipayTradeCancelRequest
{
/**
* 统一收单交易撤销接口
**/
private $bizContent;
private $apiParas = array ();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion = "1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt = false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas[ "biz_content" ] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.cancel";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl = $notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl = $returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion = $apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt = $needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.close request
*
* @author auto create
* @since 1.0, 2018-07-13 17:18:06
*/
class AlipayTradeCloseRequest
{
/**
* 统一收单交易关闭接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.close";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.create request
*
* @author auto create
* @since 1.0, 2018-09-01 17:05:01
*/
class AlipayTradeCreateRequest
{
/**
* 商户通过该接口进行交易的创建下单
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.create";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.trade.customs.declare request
*
* @author auto create
* @since 1.0, 2016-12-08 00:48:24
*/
class AlipayTradeCustomsDeclareRequest
{
/**
* 统一收单报关接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.customs.declare";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.trade.customs.query request
*
* @author auto create
* @since 1.0, 2018-03-02 14:37:16
*/
class AlipayTradeCustomsQueryRequest
{
/**
* 查询报关详细信息
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.customs.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.trade.fastpay.refund.query request
*
* @author auto create
* @since 1.0, 2018-07-25 17:25:00
*/
class AlipayTradeFastpayRefundQueryRequest
{
/**
* 商户可使用该接口查询自已通过alipay.trade.refund提交的退款请求是否执行成功。
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.fastpay.refund.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.trade.order.settle request
*
* @author auto create
* @since 1.0, 2018-07-13 17:18:06
*/
class AlipayTradeOrderSettleRequest
{
/**
* 统一收单交易结算接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.order.settle";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.trade.orderinfo.sync request
*
* @author auto create
* @since 1.0, 2018-07-23 11:40:00
*/
class AlipayTradeOrderinfoSyncRequest
{
/**
* 支付宝订单信息同步接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.orderinfo.sync";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.page.pay request
*
* @author auto create
* @since 1.0, 2018-08-14 15:31:43
*/
class AlipayTradePagePayRequest
{
/**
* 统一收单下单并支付页面接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.page.pay";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.pay request
*
* @author auto create
* @since 1.0, 2018-08-31 11:20:00
*/
class AlipayTradePayRequest
{
/**
* 用于在线下场景交易一次创建并支付掉
修改路由策略到R
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.pay";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.precreate request
*
* @author auto create
* @since 1.0, 2018-06-14 17:32:25
*/
class AlipayTradePrecreateRequest
{
/**
* 收银员通过收银台或商户后台调用支付宝接口,生成二维码后,展示给伤脑筋户,由用户扫描二维码完成订单支付。
修改路由策略到R
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.precreate";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,121 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.query request
*
* @author auto create
* @since 1.0, 2018-05-11 18:28:47
*/
class AlipayTradeQueryRequest
{
/**
* 统一收单线下交易查询
* 修改路由策略到R
**/
private $bizContent;
private $apiParas = array ();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion = "1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt = false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas[ "biz_content" ] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl = $notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl = $returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion = $apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt = $needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.refund request
*
* @author auto create
* @since 1.0, 2018-09-01 17:20:00
*/
class AlipayTradeRefundRequest
{
/**
* 统一收单交易退款接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.refund";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.trade.vendorpay.devicedata.upload request
*
* @author auto create
* @since 1.0, 2016-12-08 00:51:39
*/
class AlipayTradeVendorpayDevicedataUploadRequest
{
/**
* 厂商支付授权时上传设备数据接口目前主要包含三星支付。com
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.vendorpay.devicedata.upload";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace addon\alipay\data\sdk\request;
/**
* ALIPAY API: alipay.trade.wap.pay request
*
* @author auto create
* @since 1.0, 2018-08-06 12:35:00
*/
class AlipayTradeWapPayRequest
{
/**
* 手机网站支付接口2.0
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.trade.wap.pay";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay as PayCommon;
/**
* 支付回调
*/
class AuthcodePay
{
/**
* 支付方式及配置
*/
public function handle($params)
{
$out_trade_no = $params[ 'out_trade_no' ] ?? '';
$auth_code_array = [ 25, 26, 27, 28, 29, 30 ];
if (!empty($out_trade_no)) {
$auth_code = $params[ 'auth_code' ];
$sub_str = substr($auth_code, 0, 2);
if (in_array($sub_str, $auth_code_array)) {
$pay = new PayCommon();
$pay_info = $pay->getPayInfo($out_trade_no)[ 'data' ] ?? [];
if (!empty($pay_info)) {
$site_id = $pay_info[ 'site_id' ] ?? 0;
$pay_model = new PayModel($site_id);
$result = $pay_model->micropay(array_merge($params, $pay_info));
return $result;
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
*/
namespace addon\alipay\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 生成支付
*/
class Pay
{
/**
* 支付方式及配置
*/
public function handle($param)
{
if ($param[ "pay_type" ] == "alipay") {
if (in_array($param[ "app_type" ], [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
$pay_model = new PayModel($param[ 'site_id' ], $param[ "app_type" ] == 'aliapp');
$res = $pay_model->pay($param);
return $res;
}
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 关闭支付
*/
class PayClose
{
/**
* 关闭支付
* @param $params
* @return \addon\alipay\model\multitype|array
*/
public function handle($params)
{
// if ($params["pay_type"] == "alipay") {
try {
$pay_model = new PayModel($params[ 'site_id' ]);
$result = $pay_model->close($params);
return $result;
} catch (\Exception $e) {
return error(-1, $e->getMessage());
} catch (\Throwable $e) {
return error(-1, $e->getMessage());
}
// }
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay as PayCommon;
/**
* 支付回调
*/
class PayNotify
{
/**
* 支付方式及配置
*/
public function handle()
{
if (isset($_POST[ 'out_trade_no' ])) {
$out_trade_no = $_POST[ 'out_trade_no' ];
$pay = new PayCommon();
$pay_info = $pay->getPayInfo($out_trade_no)[ 'data' ];
if (empty($pay_info)) return false;
if ($_POST[ 'total_amount' ] != $pay_info[ 'pay_money' ]) {
return false;
}
$mch_info = empty($pay_info[ 'mch_info' ]) ? [] : json_decode($pay_info[ 'mch_info' ], true);
$pay_model = new PayModel($pay_info[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
$pay_model->payNotify();
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Config as ConfigModel;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay;
/**
* 查询支付结果
*/
class PayOrderQuery
{
public function handle(array $params)
{
$pay_info = ( new Pay() )->getInfo([ [ 'id', '=', $params[ 'relate_id' ] ] ])[ 'data' ];
if (!empty($pay_info)) {
$config_model = new ConfigModel();
$pay_config = $config_model->getPayConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
if (!empty($pay_config) && $pay_config[ 'pay_status' ] != 2) {
$pay_common = new PayModel($pay_info[ 'site_id' ]);
$pay_common->orderQuery($pay_info);
}
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 原路退款
*/
class PayRefund
{
/**
* 关闭支付
*/
public function handle($params)
{
if ($params[ "pay_info" ][ "pay_type" ] == "alipay") {
$mch_info = empty($params[ 'pay_info' ][ 'mch_info' ]) ? [] : json_decode($params[ 'pay_info' ][ 'mch_info' ], true);
$pay_model = new PayModel($params[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
$result = $pay_model->refund($params);
return $result;
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay;
use addon\alipay\model\Config;
class PayTransfer
{
public function handle(array $params)
{
if ($params[ 'transfer_type' ] == 'alipay') {
$pay = new Pay($params[ 'site_id' ]);
$config_model = new Config();
$config_result = $config_model->getPayConfig($params[ 'site_id' ]);
$config = $config_result[ "data" ];
if (!empty($config[ 'value' ])) {
$config_info = $config[ "value" ];
$countersign_type = $config_info['countersign_type'] ?? 0;
if ($countersign_type == 0) {
$res = $pay->payTransfer($params);
return $res;
} else {
$res = $pay->payNewTransfer($params);
return $res;
}
} else {
$res = $pay->payTransfer($params);
return $res;
}
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Config;
/**
* 支付方式 (后台调用)
*/
class PayType
{
/**
* 支付方式及配置
*/
public function handle($param)
{
$app_type = $param['app_type'] ?? '';
if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
return '';
}
if ($app_type != 'aliapp') {
$config_model = new Config();
$config_result = $config_model->getPayConfig($param[ 'site_id' ]);
$config = $config_result[ "data" ][ "value" ] ?? [];
$pay_status = $config[ "pay_status" ] ?? 0;
if ($pay_status == 0) {
return '';
}
}
}
$info = array (
"pay_type" => "alipay",
"pay_type_name" => "支付宝支付",
"edit_url" => "alipay://shop/pay/config",
"shop_url" => "alipay://shop/pay/config",
"logo" => "addon/alipay/icon.png",
"desc" => "支付宝网站(www.alipay.com) 是国内先进的网上支付平台。"
);
return $info;
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Config;
class TransferType
{
public function handle(array $param)
{
$app_type = $param['app_type'] ?? '';
if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp" ])) {
return '';
}
$config_model = new Config();
$config_result = $config_model->getPayConfig($param[ 'site_id' ]);
$config = $config_result[ "data" ][ "value" ] ?? [];
$transfer_status = $config[ "transfer_status" ] ?? 0;
if ($transfer_status == 0) {
return '';
}
}
$info = array (
"type" => "alipay",
"type_name" => "支付宝",
);
return $info;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
*/
namespace addon\alipay\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return error(-1, "系统插件不得删除");
}
}

BIN
src/addon/alipay/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,96 @@
<?php
/**
*/
namespace addon\alipay\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 支付宝支付配置
*/
class Config extends BaseModel
{
private $encrypt = '******';
/**
* 设置支付配置
* @param $data
* @param int $site_id
* @param string $app_module
* @return array
*/
public function setPayConfig($data, $site_id = 0, $app_module = 'shop')
{
$config = new ConfigModel();
// 未加密前的数据
$original_config = $this->getPayConfig($site_id)[ 'data' ][ 'value' ];
// 检测数据是否发生变化,如果没有变化,则保持未加密前的数据
if (!empty($data[ 'private_key' ]) && $data[ 'private_key' ] == $this->encrypt) {
$data[ 'private_key' ] = $original_config[ 'private_key' ]; // 应用私钥
}
if (!empty($data[ 'public_key' ]) && $data[ 'public_key' ] == $this->encrypt) {
$data[ 'public_key' ] = $original_config[ 'public_key' ]; // 应用公钥
}
if (!empty($data[ 'alipay_public_key' ]) && $data[ 'alipay_public_key' ] == $this->encrypt) {
$data[ 'alipay_public_key' ] = $original_config[ 'alipay_public_key' ]; // 支付宝公钥
}
if (!empty($data[ 'public_key_crt' ]) && $data[ 'public_key_crt' ] == $this->encrypt) {
$data[ 'public_key_crt' ] = $original_config[ 'public_key_crt' ]; // 应用公钥证书
}
if (!empty($data[ 'alipay_public_key_crt' ]) && $data[ 'alipay_public_key_crt' ] == $this->encrypt) {
$data[ 'alipay_public_key_crt' ] = $original_config[ 'alipay_public_key_crt' ]; // 支付宝公钥证书
}
if (!empty($data[ 'alipay_with_crt' ]) && $data[ 'alipay_with_crt' ] == $this->encrypt) {
$data[ 'alipay_with_crt' ] = $original_config[ 'alipay_with_crt' ]; // 支付宝根证书
}
$res = $config->setConfig($data, '支付宝支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
return $res;
}
/**
* 获取支付配置
* @param int $site_id
* @param string $app_module
* @param bool $need_encrypt 是否需要加密数据true加密、false不加密
* @return array
*/
public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false)
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
if ($need_encrypt) {
// 加密敏感信息
if (!empty($res[ 'data' ][ 'value' ][ 'private_key' ])) {
$res[ 'data' ][ 'value' ][ 'private_key' ] = $this->encrypt; // 应用私钥
}
if (!empty($res[ 'data' ][ 'value' ][ 'public_key' ])) {
$res[ 'data' ][ 'value' ][ 'public_key' ] = $this->encrypt; // 应用公钥
}
if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key' ])) {
$res[ 'data' ][ 'value' ][ 'alipay_public_key' ] = $this->encrypt; // 支付宝公钥
}
if (!empty($res[ 'data' ][ 'value' ][ 'public_key_crt' ])) {
$res[ 'data' ][ 'value' ][ 'public_key_crt' ] = $this->encrypt; // 应用公钥证书
}
if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key_crt' ])) {
$res[ 'data' ][ 'value' ][ 'alipay_public_key_crt' ] = $this->encrypt; // 支付宝公钥证书
}
if (!empty($res[ 'data' ][ 'value' ][ 'alipay_with_crt' ])) {
$res[ 'data' ][ 'value' ][ 'alipay_with_crt' ] = $this->encrypt; // 支付宝根证书
}
}
return $res;
}
}

View File

@@ -0,0 +1,486 @@
<?php
/**
*/
namespace addon\alipay\model;
use addon\alipay\data\sdk\AopClient;
use addon\alipay\data\sdk\request\AlipayFundTransToaccountTransferRequest;
use addon\alipay\data\sdk\request\AlipayTradeAppPayRequest;
use addon\alipay\data\sdk\request\AlipayTradeCloseRequest;
use addon\alipay\data\sdk\request\AlipayTradeCreateRequest;
use addon\alipay\data\sdk\request\AlipayTradePagePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeRefundRequest;
use addon\alipay\data\sdk\request\AlipayTradeWapPayRequest;
use addon\alipay\data\sdk\request\AlipayTradePrecreateRequest;
use addon\alipay\data\sdk\request\AlipayTradePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeQueryRequest;
use app\model\BaseModel;
use app\model\system\Cron;
use app\model\system\Pay as PayCommon;
use addon\alipay\data\sdk\request\AlipayFundTransUniTransferRequest;
use addon\alipay\data\sdk\AopCertClient;
use app\model\system\Pay as PayModel;
use addon\aliapp\model\Config as AliappConfig;
use think\facade\Log;
/**
* 支付宝支付配置
*/
class Pay extends BaseModel
{
public $aop;
private $is_aliapp = 0;
/**
*
* @param $site_id
* @param int $is_aliapp 是否是小程序
*/
function __construct($site_id, $is_aliapp = 0)
{
$this->is_aliapp = $is_aliapp;
try {
// 获取支付宝支付参数(统一支付到平台账户)
if ($is_aliapp) {
$config_info = ( new AliappConfig() )->getAliappConfig($site_id)[ 'data' ][ 'value' ];
} else {
$config_info = ( new Config() )->getPayConfig($site_id)[ 'data' ][ 'value' ];
}
if (!empty($config_info)) {
$countersign_type = $config_info[ 'countersign_type' ] ?? 0;
if ($countersign_type == 1) {
$appCertPath = $config_info[ "public_key_crt" ] ?? "";
$alipayCertPath = $config_info[ "alipay_public_key_crt" ] ?? "";
$rootCertPath = $config_info[ "alipay_with_crt" ] ?? "";
$this->aop = new AopCertClient();
//调用getPublicKey从支付宝公钥证书中提取公钥
$this->aop->alipayrsaPublicKey = $this->aop->getPublicKey($alipayCertPath);
//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$this->aop->isCheckAlipayPublicCert = false;
//调用getCertSN获取证书序列号
$this->aop->appCertSN = $this->aop->getCertSN($appCertPath);
//调用getRootCertSN获取支付宝根证书序列号
$this->aop->alipayRootCertSN = $this->aop->getRootCertSN($rootCertPath);
} else {
// 获取支付宝支付参数(统一支付到平台账户)
$this->aop = new AopClient();
$this->aop->alipayrsaPublicKey = $config_info[ 'public_key' ] ?? "";
$this->aop->alipayPublicKey = $config_info[ 'alipay_public_key' ] ?? "";
}
$this->aop->appId = $config_info[ "app_id" ] ?? "";
$this->aop->rsaPrivateKey = $config_info[ 'private_key' ] ?? "";
$this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$this->aop->apiVersion = '1.0';
$this->aop->signType = 'RSA2';
$this->aop->postCharset = 'UTF-8';
$this->aop->format = 'json';
}
// else{
// return $this->error('', '支付宝支付未配置');
// }
} catch (\Exception $e) {
return $this->error('', '支付宝配置错误');
}
}
/**
* 生成支付
* @param $param
* @return array
*/
public function pay($param)
{
//构造要请求的参数数组,无需改动
$parameter = array (
"out_trade_no" => $param[ "out_trade_no" ],
"subject" => str_sub($param[ "pay_body" ], 15),
"total_amount" => (float) $param[ "pay_money" ],
"body" => str_sub($param[ "pay_body" ], 60),
"product_code" => 'FAST_INSTANT_TRADE_PAY',
);
switch ( $param[ "app_type" ] ) {
case "h5":
$request = new AlipayTradeWapPayRequest();
break;
case "pc":
$request = new AlipayTradePagePayRequest();
break;
case "app":
$request = new AlipayTradeAppPayRequest();
break;
case 'wechat':
$request = new AlipayTradeWapPayRequest();
break;
case 'cashier':
$request = new AlipayTradePrecreateRequest();
break;
case 'aliapp':
$parameter[ 'product_code' ] = 'FACE_TO_FACE_PAYMENT';
$member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'ali_openid');
if (empty($member_info)) return $this->error(-1, '未获取到会员信息');
$parameter[ 'buyer_id' ] = $member_info[ 'ali_openid' ];
$request = new AlipayTradeCreateRequest();
break;
}
$parameter = json_encode($parameter);
$request->setBizContent($parameter);
$request->SetReturnUrl($param[ "return_url" ]);
$request->SetNotifyUrl($param[ "notify_url" ]);
///绑定商户数据
$pay_model = new PayModel();
$pay_model->bindMchPay($param[ "out_trade_no" ], [ "is_aliapp" => $this->is_aliapp ]);
try {
if ($param[ "app_type" ] == 'h5' || $param[ "app_type" ] == 'wechat' || $param[ "app_type" ] == 'pc') {
$result = $this->aop->pageExecute($request, 'get');
return $this->success([
'type' => 'url',
'data' => $result
]);
} elseif ($param[ "app_type" ] == 'app') {
$result = $this->aop->sdkExecute($request);
if (strpos(get_class($this->aop), 'AopClient') !== false) {
return $this->success([
'type' => 'url',
'data' => $result
]);
}
} else {
$result = $this->aop->execute($request);
}
if ($result === false) return $this->error('', '支付宝发起支付失败');
} catch (\Exception $e) {
return $this->error('', $e->getMessage());
}
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
switch ( $param[ "app_type" ] ) {
case 'cashier':
return $this->success([
'type' => 'qrcode',
'data' => [
'qrcode' => $result->$responseNode->qr_code
]
]);
break;
case 'aliapp':
return $this->success([
'type' => 'data',
'data' => [
'orderInfo' => $result->$responseNode->trade_no
]
]);
break;
default:
return $this->success();
}
} else {
return $this->error("", $result->$responseNode->sub_msg);
}
}
/**
* 支付关闭
* @param $param
* @return array
* @throws \think\Exception
*/
public function close($param)
{
$parameter = array (
"out_trade_no" => $param[ "out_trade_no" ]
);
// 建立请求
$request = new AlipayTradeCloseRequest();
$request->setBizContent(json_encode($parameter));
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
return $this->success();
} else {
$sub_code = $result->$responseNode->sub_code;
$data = [];
if(in_array($sub_code, ['ACQ.TRADE_STATUS_ERROR', 'ACQ.REASON_TRADE_STATUS_INVALID', 'ACQ.REASON_ILLEGAL_STATUS'])){
$pay_order_result = $this->get($param[ "out_trade_no" ]);
if(!empty($pay_order_result) && $pay_order_result['code'] >= 0){
if($pay_order_result['data']['trade_status'] == 'TRADE_SUCCESS' || $pay_order_result['data']['trade_status'] == 'TRADE_FINISHED'){
$data['is_paid'] = 1;
}
}
}
return $this->error($data, $result->$responseNode->sub_msg);
}
}
/**
* 支付宝支付原路返回
* @param array $param 支付参数
* @return array
* @throws \think\Exception
*/
public function refund($param)
{
$pay_info = $param[ "pay_info" ];
$refund_no = $param[ "refund_no" ];
$out_trade_no = $pay_info[ "trade_no" ] ?? '';
$refund_fee = $param[ "refund_fee" ];
$parameter = array (
'trade_no' => $out_trade_no,
'refund_amount' => sprintf("%.2f", $refund_fee),
'out_request_no' => $refund_no
);
// 建立请求
$request = new AlipayTradeRefundRequest ();
$request->setBizContent(json_encode($parameter));
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
return $this->success();
} else {
return $this->error("", $result->$responseNode->sub_msg);
}
}
/**
* 支付宝转账
* @param $param
* @return array
*/
public function payTransfer($param)
{
try {
$config_model = new Config();
$config_result = $config_model->getPayConfig($param[ 'site_id' ]);
if ($config_result[ 'code' ] < 0) return $config_result;
$config = $config_result[ 'data' ][ 'value' ];
if (empty($config)) return $this->error([], '未配置支付宝支付');
if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
$parameter = [
'out_biz_no' => $param[ 'out_trade_no' ],
'payee_type' => 'ALIPAY_LOGONID',
'payee_account' => $param[ "account_number" ],
'amount' => sprintf("%.2f", $param[ 'amount' ]),
'payee_real_name' => $param[ "real_name" ],
'remark' => $param[ "desc" ]
];
// 建立请求
$request = new AlipayFundTransToaccountTransferRequest();
$request->setBizContent(json_encode($parameter));
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
return $this->success([
'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
'payment_no' => $result->$responseNode->order_id, // 微信付款单号
'payment_time' => date_to_time($result->$responseNode->pay_date) // 付款成功时间
]);
} else {
return $this->error([], $result->$responseNode->sub_msg);
}
} catch (\Exception $e) {
return $this->error([], $e->getMessage());
}
}
/**
* 异步完成支付
* @param $param
*/
public function payNotify()
{
// Log::write('pay_notifiy_log:alipay:'.json_encode(input()), 'notice');
try {
$res = $this->aop->rsaCheckV1($_POST, $this->aop->alipayrsaPublicKey, $this->aop->signType);
if ($res) { // 验证成功
$out_trade_no = $_POST[ 'out_trade_no' ];
// 支付宝交易号
$trade_no = $_POST[ 'trade_no' ];
// 交易状态
$trade_status = $_POST[ 'trade_status' ];
$pay_common = new PayCommon();
if ($trade_status == "TRADE_SUCCESS") {
$retval = $pay_common->onlinePay($out_trade_no, "alipay", $trade_no, "alipay");
}
echo "success";
} else {
// 验证失败
echo "fail";
}
} catch (\Exception $e) {
echo "fail";
}
}
public function payNewTransfer($param)
{
try {
$config_model = new Config();
$config_result = $config_model->getPayConfig($param[ 'site_id' ]);
if ($config_result[ 'code' ] < 0) return $config_result;
$config = $config_result[ 'data' ][ 'value' ];
if (empty($config)) return $this->error([], '未配置支付宝支付');
if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
$parameter = [
'out_biz_no' => $param[ 'out_trade_no' ],
'trans_amount' => sprintf("%.2f", $param[ 'amount' ]),
'product_code' => 'TRANS_ACCOUNT_NO_PWD',
'biz_scene' => 'DIRECT_TRANSFER',
'order_title' => '支付宝转账',
'remark' => $param[ "desc" ],
'payee_info' => [
'identity' => $param[ "account_number" ],
'identity_type' => "ALIPAY_LOGON_ID",
'name' => $param[ "real_name" ]
]
];
// 建立请求
$request = new AlipayFundTransUniTransferRequest();
$request->setBizContent(json_encode($parameter));
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
return $this->success([
'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
'payment_no' => $result->$responseNode->order_id, // 微信付款单号
'payment_time' => date_to_time($result->$responseNode->trans_date) // 付款成功时间
]);
} else {
return $this->error([], $result->$responseNode->sub_msg);
}
} catch (\Exception $e) {
return $this->error([], $e->getMessage());
}
}
/**
* 付款码支付
* @param $param
* @return array|mixed|void
*/
public function micropay($param)
{
try {
//构造要请求的参数数组,无需改动
$parameter = array (
"out_trade_no" => $param[ "out_trade_no" ],
"subject" => str_sub($param[ "pay_body" ], 15),
"total_amount" => (float) $param[ "pay_money" ],
"scene" => "bar_code",
"auth_code" => $param[ 'auth_code' ],
);
$parameter = json_encode($parameter);
$request = new AlipayTradePayRequest();
$request->setBizContent($parameter);
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
Log::write('支付宝—付款码支付result' . json_encode($result));
Log::write('支付宝—付款码支付resultCode' . json_encode($resultCode));
if (!empty($resultCode)) {
if ($resultCode == 10000) {
$pay_common = new PayModel();
return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
} else if ($resultCode == 10003) {
// 等待用户付款
( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
}
} else {
return $this->error([], $result->$responseNode->sub_msg);
}
} catch (\Exception $e) {
return $this->error([], $e->getMessage());
}
}
// todo 查询交易信息【AlipayTradeQueryRequest】 https://opendocs.alipay.com/open/194/106039?pathHash=5b8cf9e6
public function orderQuery($param)
{
try {
//构造要请求的参数数组,无需改动
$parameter = array (
"out_trade_no" => $param[ "out_trade_no" ],
);
$parameter = json_encode($parameter);
$request = new AlipayTradeQueryRequest();
$request->setBizContent($parameter);
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
Log::write('alipay_orderQuery' . json_encode($result));
Log::write('alipay_orderQuery_$resultCode' . json_encode($resultCode));
if (!empty($resultCode) && $resultCode == 10000) {
if ($result->$responseNode->trade_status == 'TRADE_SUCCESS') {
$pay_common = new PayModel();
return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
} else {
( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
}
} else {
return $this->error([], $result->$responseNode->sub_msg);
}
} catch (\Exception $e) {
return $this->error([], $e->getMessage());
}
}
/**
* 查询订单信息
* @param $out_trade_no
* @return array
* @throws \think\Exception
*/
public function get($out_trade_no)
{
$parameter = array (
"out_trade_no" => $out_trade_no
);
// 建立请求
$request = new AlipayTradeQueryRequest();
$request->setBizContent(json_encode($parameter));
$result = $this->aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) {
return $this->success(json_decode(json_encode($result->$responseNode), true));
} else {
return $this->error([], $result->$responseNode->sub_msg);
}
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
*/
namespace addon\alipay\shop\controller;
use addon\alipay\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
use think\facade\Config;
use app\model\upload\Upload;
/**
* 支付宝 控制器
*/
class Pay extends BaseShop
{
public function config()
{
$config_model = new ConfigModel();
if (request()->isJson()) {
$app_id = input("app_id", "");//支付宝应用ID (支付宝分配给开发者的应用ID)
$private_key = input("private_key", "");//应用私钥
$public_key = input("public_key", "");//应用公钥
$alipay_public_key = input("alipay_public_key", "");//支付宝公钥
$app_type = input("app_type", "");//支持端口 如web app
$pay_status = input("pay_status", 0);//支付启用状态
$refund_status = input("refund_status", 0);//退款启用状态
$transfer_status = input("transfer_status", 0);//转账启用状态
$public_key_crt = input("public_key_crt", "");
$alipay_public_key_crt = input("alipay_public_key_crt", "");
$alipay_with_crt = input("alipay_with_crt", "");
$countersign_type = input("countersign_type", 0);//加签模式
$data = array (
"app_id" => $app_id,
"private_key" => $private_key,
"public_key" => $public_key,
"alipay_public_key" => $alipay_public_key,
"refund_status" => $refund_status,
"pay_status" => $pay_status,
"transfer_status" => $transfer_status,
"app_type" => $app_type,
"public_key_crt" => $public_key_crt,
"alipay_public_key_crt" => $alipay_public_key_crt,
"alipay_with_crt" => $alipay_with_crt,
"countersign_type" => $countersign_type
);
$result = $config_model->setPayConfig($data, $this->site_id, $this->app_module);
return $result;
} else {
$info = $config_model->getPayConfig($this->site_id, $this->app_module, true)[ 'data' ][ 'value' ];
if (!empty($info)) {
$app_type_arr = [];
if (!empty($info[ 'app_type' ])) {
$app_type_arr = explode(',', $info[ 'app_type' ]);
}
$info[ 'app_type_arr' ] = $app_type_arr;
if (empty($info[ 'countersign_type' ])) {
$info[ 'countersign_type' ] = 0;
}
}
$this->assign("info", $info);
$this->assign("app_type", Config::get("app_type"));
return $this->fetch("pay/config");
}
}
/**
* 上传微信支付证书
*/
public function uploadAlipayCrt()
{
$upload_model = new Upload();
$site_id = request()->siteid();
$name = input("name", "");
$extend_type = [ 'crt' ];
$param = array (
"name" => "file",
"extend_type" => $extend_type
);
$site_id = max($site_id, 0);
$result = $upload_model->setPath("common/alipay/crt/" . $site_id . "/")->file($param);
return $result;
}
}

View File

@@ -0,0 +1,294 @@
<style>
.input-text span{margin-right: 15px;}
</style>
<div class="layui-form form-wrap">
<div class="layui-form-item balance-boday">
<label class="layui-form-label">加签模式:</label>
<div class="layui-input-block">
<div class="layui-input-inline">
{if $info}
<input type="radio" name="countersign_type" lay-filter="type" value="0" title="公钥" autocomplete="off" class="layui-input len-long" {if $info.countersign_type == 0} checked {/if} >
<input type="radio" name="countersign_type" lay-filter="type" value="1" title="公钥证书" autocomplete="off" class="layui-input len-long" {if $info.countersign_type == 1} checked {/if} >
{else/}
<input type="radio" name="countersign_type" lay-filter="type" value="0" title="公钥" autocomplete="off" class="layui-input len-long" checked>
<input type="radio" name="countersign_type" lay-filter="type" value="1" title="公钥证书" autocomplete="off" class="layui-input len-long">
{/if}
</div>
</div>
<div class="word-aux">支付宝配置规则加签模式。</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝应用ID</label>
<div class="layui-input-block">
<input name="app_id" type="text" value="{$info.app_id ?? ''}" class="layui-input len-long">
</div>
<div class="word-aux"><span>[API_ID]</span>支付宝分配给开发者的应用ID</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">应用私钥:</label>
<div class="layui-input-block">
<textarea name="private_key" class="layui-textarea len-long" placeholder="请输入应用私钥">{$info.private_key ?? ''}</textarea>
</div>
</div>
{if empty($info) || $info.countersign_type == 0}
<div class="countersign_type_zero" >
<div class="layui-form-item " >
<label class="layui-form-label">应用公钥:</label>
<div class="layui-input-block">
<textarea name="public_key" class="layui-textarea len-long" placeholder="请输入应用公钥">{$info.public_key ?? ''}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝公钥:</label>
<div class="layui-input-block">
<textarea name="alipay_public_key" class="layui-textarea len-long" placeholder="请输入支付宝公钥">{$info.alipay_public_key ?? ''}</textarea>
</div>
</div>
</div>
<div class="countersign_type_one" style="display: none">
<div class="layui-form-item ">
<label class="layui-form-label">应用公钥证书:</label>
<div class="layui-input-block">
{notempty name="$info.public_key_crt"}
<p class="file-upload">已上传</p>
{else/}
<p class="file-upload">未上传</p>
{/notempty}
<button type="button" class="layui-btn" id="public_key_upload">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<input type="hidden" name="public_key_crt" class="layui-input len-long" value="{$info.public_key_crt ?? ''}">
</div>
<div class="word-aux">上传appCertPublicKey文件</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝公钥证书:</label>
<div class="layui-input-block">
{notempty name="$info.alipay_public_key_crt"}
<p class="file-upload">已上传</p>
{else/}
<p class="file-upload">未上传</p>
{/notempty}
<button type="button" class="layui-btn" id="alipay_public_key_upload">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<input type="hidden" name="alipay_public_key_crt" class="layui-input len-long" value="{$info.alipay_public_key_crt ?? ''}">
</div>
<div class="word-aux">上传alipayCertPublicKey文件</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝根证书:</label>
<div class="layui-input-block">
{notempty name="$info.alipay_with_crt"}
<p class="file-upload">已上传</p>
{else/}
<p class="file-upload">未上传</p>
{/notempty}
<button type="button" class="layui-btn" id="alipay_with_upload">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<input type="hidden" name="alipay_with_crt" class="layui-input len-long" value="{$info.alipay_with_crt ?? ''}">
</div>
<div class="word-aux">上传alipayRootCert文件</div>
</div>
</div>
{else/}
<div class="countersign_type_zero" style="display: none">
<div class="layui-form-item " >
<label class="layui-form-label">应用公钥:</label>
<div class="layui-input-block">
<textarea name="public_key" class="layui-textarea len-long" placeholder="请输入应用公钥">{$info.public_key ?? ''}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝公钥:</label>
<div class="layui-input-block">
<textarea name="alipay_public_key" class="layui-textarea len-long" placeholder="请输入支付宝公钥">{$info.alipay_public_key ?? ''}</textarea>
</div>
</div>
</div>
<div class="countersign_type_one">
<div class="layui-form-item ">
<label class="layui-form-label">应用公钥证书:</label>
<div class="layui-input-block">
{notempty name="$info.public_key_crt"}
<p class="file-upload">已上传</p>
{else/}
<p class="file-upload">未上传</p>
{/notempty}
<button type="button" class="layui-btn" id="public_key_upload">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<input type="hidden" name="public_key_crt" class="layui-input len-long" value="{$info.public_key_crt ?? ''}">
</div>
<div class="word-aux">上传appCertPublicKey文件</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝公钥证书:</label>
<div class="layui-input-block">
{notempty name="$info.alipay_public_key_crt"}
<p class="file-upload">已上传</p>
{else/}
<p class="file-upload">未上传</p>
{/notempty}
<button type="button" class="layui-btn" id="alipay_public_key_upload">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<input type="hidden" name="alipay_public_key_crt" class="layui-input len-long" value="{$info.alipay_public_key_crt ?? ''}">
</div>
<div class="word-aux">上传alipayCertPublicKey文件</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">支付宝根证书:</label>
<div class="layui-input-block">
{notempty name="$info.alipay_with_crt"}
<p class="file-upload">已上传</p>
{else/}
<p class="file-upload">未上传</p>
{/notempty}
<button type="button" class="layui-btn" id="alipay_with_upload">
<i class="layui-icon">&#xe67c;</i>上传文件
</button>
<input type="hidden" name="alipay_with_crt" class="layui-input len-long" value="{$info.alipay_with_crt ?? ''}">
</div>
<div class="word-aux">上传alipayRootCert文件</div>
</div>
</div>
{/if}
<div class="layui-form-item">
<label class="layui-form-label">支持端口:</label>
<div class="input-text">
{foreach $app_type as $app_type_k => $app_type_v}
{if condition="$app_type_v['name'] !='微信小程序' && $app_type_v['name'] !='微信公众号'"}
<span>{$app_type_v['name']}</span>
{/if}
{/foreach}
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否启用支付:</label>
<div class="layui-input-block">
<input type="checkbox" name="pay_status" value="1" lay-skin="switch" {if condition="$info && $info.pay_status == 1"} checked {/if} />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否启用退款:</label>
<div class="layui-input-block">
<input type="checkbox" name="refund_status" value="1" lay-skin="switch" {if condition="$info && $info.refund_status == 1"} checked {/if} />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否启用转账:</label>
<div class="layui-input-block">
<input type="checkbox" name="transfer_status" value="1" lay-skin="switch" {if condition="$info && $info.transfer_status == 1"} checked {/if} />
</div>
</div>
<div class="form-row">
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
</div>
</div>
<script>
layui.use('form', function() {
var form = layui.form;
var repeat_flag = false; //防重复标识
form.render();
layui.form.on('radio(type)', function(data){
if(data.value == 0){
$(".countersign_type_zero").show();
$(".countersign_type_one").hide();
}else{
$(".countersign_type_one").show();
$(".countersign_type_zero").hide();
}
});
var public_key_upload = new Upload({
elem: '#public_key_upload',
url: ns.url("alipay://shop/pay/uploadalipaycrt"), //改成您自己的上传接口
accept: 'file',
callback:function (res) {
if (res.code >= 0) {
$("input[name='public_key_crt']").val(res.data.path);
$("input[name='public_key_crt']").siblings(".file-upload").text("已上传");
}
}
});
var alipay_public_key_upload = new Upload({
elem: '#alipay_public_key_upload',
url: ns.url("alipay://shop/pay/uploadalipaycrt"), //改成您自己的上传接口
accept: 'file',
callback:function (res) {
if (res.code >= 0) {
$("input[name='alipay_public_key_crt']").val(res.data.path);
$("input[name='alipay_public_key_crt']").siblings(".file-upload").text("已上传");
}
}
});
var alipay_with_upload = new Upload({
elem: '#alipay_with_upload',
url: ns.url("alipay://shop/pay/uploadalipaycrt"), //改成您自己的上传接口
accept: 'file',
callback:function (res) {
if (res.code >= 0) {
$("input[name='alipay_with_crt']").val(res.data.path);
$("input[name='alipay_with_crt']").siblings(".file-upload").text("已上传");
}
}
});
/**
* 监听提交
*/
form.on('submit(save)', function(data) {
if (repeat_flag) return false;
repeat_flag = true;
$.ajax({
url: ns.url("alipay://shop/pay/config"),
data: data.field,
dataType: 'JSON',
type: 'POST',
success: function(res){
repeat_flag = false;
if (res.code == 0) {
layer.confirm('编辑成功', {
title:'操作提示',
btn: ['返回列表', '继续编辑'],
yes: function(index, layero) {
location.hash = ns.hash("shop/config/pay");
layer.close(index);
},
btn2: function(index, layero) {
layer.close(index);
}
});
}else{
layer.msg(res.message);
}
}
});
});
});
function back(){
location.hash = ns.hash("shop/config/pay");
}
</script>

View File

@@ -0,0 +1,6 @@
<?php
return [
'template' => [],
'util' => [],
'link' => [],
];

View File

@@ -0,0 +1,34 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
//短信方式
'SmsType' => [
'addon\alisms\event\SmsType'
],
'DoEditSmsMessage' => [
'addon\alisms\event\DoEditSmsMessage'
],
'SendSms' => [
'addon\alisms\event\SendSms'
],
//启用回调,使用这个短信,就要关闭其他短信插件
'EnableCallBack' => [
'addon\alisms\event\EnableCallBack'
],
//查询启用的短信插件
'EnableSms' => [
'addon\alisms\event\EnableSms'
],
'SmsTemplateInfo' => [
'addon\alisms\event\SmsTemplateInfo'
]
],
'subscribe' => [
],
];

View File

@@ -0,0 +1,12 @@
<?php
return [
'name' => 'alisms',
'title' => '阿里云短信',
'description' => '阿里云短信功能',
'type' => 'tool', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1',
'version_no' => '100',
'content' => '',
];

View File

@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | 平台端菜单设置
// +----------------------------------------------------------------------
return [
[
'name' => 'ALI_SMS_CONFIG',
'title' => '短信配置',
'url' => 'alisms://shop/sms/config',
'parent' => 'CONFIG_BASE',
'is_show' => 1,
'is_control' => 1,
'is_icon' => 0,
'picture' => '',
'picture_select' => '',
'sort' => 98,
],
[
'name' => 'MESSAGE_SMS_EDIT',
'title' => '编辑短信模板',
'url' => 'alisms://shop/message/edit',
'parent' => 'MESSAGE_LISTS',
'is_show' => 0,
'picture' => '',
'picture_select' => '',
'sort' => 1,
'child_list' => [
],
],
];

View File

@@ -0,0 +1,26 @@
<?php
namespace addon\alisms\event;
use addon\alisms\model\Config as ConfigModel;
/**
* 短信模板 (后台调用)
*/
class DoEditSmsMessage
{
/**
* 短信发送方式方式及配置
*/
public function handle($data)
{
$config_model = new ConfigModel();
$config_result = $config_model->getSmsConfig($data['site_id']);
$config = $config_result["data"];
if ($config["is_use"] == 1) {
return ["edit_url" => "alisms://shop/message/edit", "shop_url" => "alisms://shop/message/edit"];
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace addon\alisms\event;
use addon\alisms\model\Config;
/**
* 使用这个短信,就要关闭其他短信插件
*/
class EnableCallBack
{
/**
* 短信发送方式方式及配置
*/
public function handle($param)
{
if ($param[ 'sms_type' ] != 'alisms') {
$config_model = new Config();
$sms_config = $config_model->getSmsConfig($param[ 'site_id' ]);
$is_use = $sms_config[ 'data' ][ 'is_use' ];
if ($is_use) {
$is_use = 0;
$res = $config_model->enableCallBack($is_use, $param[ 'site_id' ]);
return $res;
}
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace addon\alisms\event;
use addon\alisms\model\Config;
/**
* 查询启用的短信插件
*/
class EnableSms
{
/**
* 短信发送方式方式及配置
*/
public function handle($param)
{
$info = array (
"sms_type" => "alisms",
"sms_type_name" => "阿里云短信",
"edit_url" => "alisms://shop/sms/config",
"shop_url" => "alisms://shop/sms/config",
"desc" => "阿里云短信服务Short Message Service支持国内和国际快速发送验证码、短信通知和推广短信服务范围覆盖全球200多个国家和地区。国内短信支持三网合一专属通道与工信部携号转网平台实时互联。电信级运维保障实时监控自动切换到达率高达99%。"
);
$config_model = new Config();
$config = $config_model->getSmsConfig($param[ 'site_id' ]);
if ($config[ 'data' ][ 'is_use' ] == 1) {
return $info;
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace addon\alisms\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace addon\alisms\event;
use addon\alisms\model\Sms;
/**
* 短信发送
*/
class SendSms
{
/**
* 短信发送方式方式及配置
* @param $param
* @return array|mixed
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
*/
public function handle($param)
{
$sms = new Sms();
$res = $sms->send($param);
return $res;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace addon\alisms\event;
use addon\alisms\model\Config;
/**
* 获取短信模板数据
*/
class SmsTemplateInfo
{
/**
* 获取短信模板数据
*/
public function handle($param)
{
$config_model = new Config();
$sms_config = $config_model->getSmsConfig($param['site_id'], 'shop');
$sms_config = $sms_config[ 'data' ];
if ($sms_config['is_use']) {
$template_info = model('message_template')->getInfo([ ['keywords', '=', $param['keywords'] ]]);
if (!empty($template_info['sms_json'])) {
return json_decode($template_info['sms_json'], true);
}
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace addon\alisms\event;
use addon\alisms\model\Config;
/**
* 短信方式 (后台调用)
*/
class SmsType
{
/**
* 短信发送方式方式及配置
*/
public function handle($param)
{
$info = array(
"sms_type" => "alisms",
"sms_type_name" => "阿里云短信",
"edit_url" => "alisms://shop/sms/config",
"shop_url" => "alisms://shop/sms/config",
"desc" => "阿里云短信服务Short Message Service支持国内和国际快速发送验证码、短信通知和推广短信服务范围覆盖全球200多个国家和地区。国内短信支持三网合一专属通道与工信部携号转网平台实时互联。电信级运维保障实时监控自动切换到达率高达99%。"
);
$config_model = new Config();
$config = $config_model->getSmsConfig($param['site_id']);
$info['status'] = $config['data']['is_use'] ?? 0;
return $info;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace addon\alisms\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

BIN
src/addon/alisms/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,58 @@
<?php
namespace addon\alisms\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 支付宝支付配置
*/
class Config extends BaseModel
{
/**
* 设置短信配置
* array $data
*/
public function setSmsConfig($data, $is_use, $site_id = 1, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->setConfig($data, '阿里云短信配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_SMS_CONFIG' ] ]);
event('EnableCallBack', [ 'sms_type' => 'alisms', 'is_use' => $is_use, 'site_id' => $site_id ]);
return $res;
}
/**
* 获取短信配置
*/
public function getSmsConfig($site_id = 1, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_SMS_CONFIG' ] ]);
return $res;
}
/**
* 设置开关
*/
public function modifyConfigIsUse($is_use, $site_id = 1, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->modifyConfigIsUse($is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_SMS_CONFIG' ] ]);
event('EnableCallBack', [ 'sms_type' => 'alisms', 'is_use' => $is_use, 'site_id' => $site_id ]);
return $res;
}
/**
* 事件修改开关状态
*/
public function enableCallBack($is_use, $site_id = 1, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->modifyConfigIsUse($is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_SMS_CONFIG' ] ]);
return $res;
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace addon\alisms\model;
use app\model\BaseModel;
use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Exceptions\InvalidArgumentException;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
use Overtrue\EasySms\Strategies\OrderStrategy;
/**
* 阿里云短信
*/
class Sms extends BaseModel
{
/**
* 短信发送
* @param array $param
* @return array|mixed
* @throws InvalidArgumentException
*/
public function send($param = [])
{
$config_model = new Config();
$config_result = $config_model->getSmsConfig($param['site_id']);
if ($config_result[ "data" ][ "is_use" ]) {
$config = $config_result[ "data" ][ "value" ];
$sms_info = $param[ "message_info" ][ "sms_json_array" ];//消息类型模板 短信模板信息
if (empty($sms_info[ "alisms" ])) return $this->error([], "消息模板尚未配置");
$sms_info = $sms_info[ "alisms" ];
$var_parse = ['name'=>$param[ "var_parse" ]['code']];//$param[ "var_parse" ];//变量解析
$account = $param[ "sms_account" ];//发送手机号
//加入阿里云短信配置
$sms_config = [
// HTTP 请求的超时时间(秒)
'timeout' => 5.0,
// 默认发送配置
'default' => [
// 网关调用策略,默认:顺序调用
'strategy' => OrderStrategy::class,
// 默认可用的发送网关
'gateways' => [ 'aliyun' ],
],
// 可用的网关配置
'gateways' => [
"aliyun" => [
'access_key_id' => $config[ "access_key_id" ],
'access_key_secret' => $config[ "access_key_secret" ],
'sign_name' => $config[ "smssign" ],
]
],
];
// $sms_info['content'] = '【聚上科技】尊敬的用户:您的校验码: ${name},工作人员不会索取,请勿泄漏。';
// $sms_info['template_id'] = 'SMS_241077505';
$sms_info['smssign'] = $config[ "smssign" ];
try {
$easySms = new EasySms($sms_config);
$res = $easySms->send($account, [
'template' => $sms_info[ "template_id" ],
'data' => $var_parse,
]);
return $this->success([ "addon" => "alisms", "addon_name" => "阿里云短信", "content" => $sms_info[ "content" ] ]);
} catch (NoGatewayAvailableException $exception) {
$message = $exception->getException('aliyun')->getMessage();
return $this->error([ "content" => $sms_info[ "content" ] ], $message ? : '短信发送异常');
}
}
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace addon\alisms\shop\controller;
use app\model\message\Message as MessageModel;
use app\model\message\MessageTemplate as MessageTemplateModel;
use app\shop\controller\BaseShop;
/**
* 阿里云短信消息管理
*/
class Message extends BaseShop
{
/**
* 编辑模板消息
* @return array|mixed|string
*/
public function edit()
{
$message_model = new MessageModel();
$keywords = 'REGISTER_CODE';//input("keywords", "");
$info_result = $message_model->getMessageInfo($this->site_id, $keywords);
$info = $info_result["data"];
if (request()->isJson()) {
if (empty($info))
return error("", "不存在的模板信息!");
$sms_is_open = input('sms_is_open', 0);
$sms_json_array = !empty($info["sms_json_array"]) ? $info["sms_json_array"] : [];//短信配置
$template_id = input("template_id", '');//短信模板id
$smssign = input("smssign", '');//短信签名
$content = input("content", '');//短信签名
$ali_array = [];
if (!empty($sms_json_array["alisms"])) {
$ali_array = $sms_json_array["alisms"];
}
$ali_array['template_id'] = $template_id;//模板ID (备注:服务商提供的模板ID)
$ali_array['content'] = $content;//模板内容 (备注:仅用于显示)
$ali_array['smssign'] = $smssign;//短信签名 (备注:请填写短信签名(如果服务商是大于请填写审核成功的签名))
$sms_json_array["alisms"] = $ali_array;
$data = array(
'sms_json' => json_encode($sms_json_array),
);
$condition = array(
["keywords", "=", $keywords]
);
$template_model = new MessageTemplateModel();
$res = $template_model->editMessageTemplate($data, $condition);
if ($res['code'] == 0) {
$res = $message_model->editMessage(['sms_is_open' => $sms_is_open, 'site_id' => $this->site_id, 'keywords' => $keywords], [
["keywords", "=", $keywords],
['site_id', '=', $this->site_id],
]);
}
return $res;
} else {
if (empty($info))
$this->error("不存在的模板信息!");
$sms_json_array = $info["sms_json_array"];//短信配置
$ali_array = [];
if (!empty($sms_json_array["alisms"])) {
$ali_array = $sms_json_array["alisms"];
}
$this->assign("info", $ali_array);
$this->assign("keywords", $keywords);
//模板变量
$message_variable_list = $info["message_json_array"];
$this->assign("message_variable_list", $message_variable_list);
$this->assign('sms_is_open', $info['sms_is_open']);
return $this->fetch('message/edit');
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace addon\alisms\shop\controller;
use addon\alisms\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
/**
* 阿里云短信 控制器
*/
class Sms extends BaseShop
{
public function config()
{
$config_model = new ConfigModel();
if (request()->isJson()) {
$access_key_id = input("access_key_id", "");//access_key_id
$access_key_secret = input("access_key_secret", "");//access_key_secret
$smssign = input("smssign", '');//短信签名
$status = input("status", 0);//启用状态
$data = array (
"access_key_id" => $access_key_id,
"access_key_secret" => $access_key_secret,
"smssign" => $smssign
);
$result = $config_model->setSmsConfig($data, $status, $this->site_id, $this->app_module);
return $result;
} else {
$info_result = $config_model->getSmsConfig($this->site_id, $this->app_module);
$info = $info_result[ "data" ];
$this->assign("info", $info);
return $this->fetch("sms/config");
}
}
}

View File

@@ -0,0 +1,102 @@
<style>
.layui-btn-primary:hover {border-color: #C9C9C9;}
.number-con {margin-right: 10px;}
.form {margin-top: 0;}
</style>
<div class="layui-form form">
<div class="layui-form-item">
<label class="layui-form-label">是否开启:</label>
<div class="layui-input-block">
<input type="checkbox" name="sms_is_open" value="1" {if $sms_is_open == 1}checked{/if} lay-skin="switch">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="required">*</span>模板CODE</label>
<div class="layui-input-block">
<input name="template_id" type="text" value="{if !empty($info)}{$info.template_id}{/if}" lay-verify="required" placeholder="短信模板ID" class="layui-input len-long">
</div>
<div class="word-aux">必须与阿里云短信模板中要使用的模版CODE一致否则无效!</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据值:</label>
<div class="layui-input-block">
{foreach $message_variable_list as $message_variable_k => $message_variable_v}
{if $message_variable_v !='站点名称'}
<button class="layui-btn layui-btn-primary number-con" onclick="clickBtn('{$message_variable_k}')">{$message_variable_v}</button>
{/if}
{/foreach}
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">短信内容:</label>
<div class="layui-input-block">
<textarea id="text_area" name="content" class="layui-textarea len-long">{if !empty($info)}{$info.content}{/if}</textarea>
</div>
<div class="word-aux">变量只能使用上方数据值中的变量,否则不会被解析</div>
</div>
<div class="form-row">
<button class="layui-btn bg-color" lay-submit lay-filter="save">保存</button>
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
</div>
<input type="hidden" name="keywords" value="{$keywords}">
</div>
<script>
layui.use('form', function() {
var form = layui.form;
var repeat_flag = false; //防重复标识
form.render();
/**
* 监听提交
*/
form.on('submit(save)', function(data) {
if (repeat_flag) return;
repeat_flag = true;
$.ajax({
dataType: 'JSON',
type: 'POST',
url: ns.url("alisms://shop/message/edit"),
data: data.field,
success: function(res){
repeat_flag = false;
if (res.code == 0) {
layer.confirm('编辑成功', {
title:'操作提示',
btn: ['返回列表', '继续操作'],
yes: function(){
location.href = ns.url("shop/message/lists")
},
btn2: function() {
location.reload();
}
});
}else{
layer.msg(res.message);
}
}
});
});
});
function back(){
location.href = ns.url("shop/message/lists");
}
function clickBtn(con) {
var txtArea = $("#text_area")[0];
var content = txtArea.value; //文本域内容
var start = txtArea.selectionStart; //光标的初始位置selectionStart选区开始位置selectionEnd选区结束位置。
txtArea.value = content.substring(0, txtArea.selectionStart) + '{' + con + '}' + content.substring(txtArea.selectionEnd, content.length);
var position = start + con.length;
$("#text_area").focus();
txtArea.setSelectionRange(position+1, position+1); //setSelectionRange()方法用来设置<input>元素当前选中的文本的开始和结束位置
}
</script>

View File

@@ -0,0 +1,82 @@
<style>
.form {margin-top: 0;}
</style>
<div class="layui-form form">
<div class="layui-form-item">
<label class="layui-form-label">是否开启:</label>
<div class="layui-input-block" id="isOpen">
<input type="checkbox" name="status" lay-filter="isOpen" value="1" lay-skin="switch" {if condition="$info.is_use == 1"} checked {/if} />
</div>
<div class="word-aux">当前使用阿里云短信配置</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">APP_KEY</label>
<div class="layui-input-block">
<input type="text" name="access_key_id" placeholder="请输入内容APP_KEY" {if $info.value } value="{$info.value.access_key_id}" {/if} autocomplete="off" class="layui-input len-long">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">SECRET_KEY</label>
<div class="layui-input-block">
<input type="text" name="access_key_secret" placeholder="请输入SECRET_KEY" {if $info.value } value="{$info.value.access_key_secret}" {/if} autocomplete="off" class="layui-input len-long">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">短信内容签名:</label>
<div class="layui-input-block">
<input type="text" name="smssign" placeholder="请输入短信内容签名" {if $info.value } value="{$info.value.smssign}" {/if} autocomplete="off" class="layui-input len-long">
</div>
</div>
<!-- 表单操作 -->
<div class="form-row">
<button class="layui-btn bg-color" lay-submit lay-filter="save">保存</button>
<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
</div>
</div>
<script>
layui.use('form', function() {
var form = layui.form,
repeat_flag = false; //防重复标识
form.render();
form.on('submit(save)', function(data) {
if (repeat_flag) return;
repeat_flag = true;
$.ajax({
url: ns.url("alisms://shop/sms/config"),
data: data.field,
dataType: 'JSON',
type: 'POST',
success: function(res) {
repeat_flag = false;
if (res.code == 0) {
layer.confirm('编辑成功', {
title:'操作提示',
btn: ['返回列表', '继续操作'],
yes: function(){
location.href = ns.url("shop/message/sms")
},
btn2: function() {
location.reload();
}
});
}else{
layer.msg(res.message);
}
}
});
});
});
function back() {
location.href = ns.url("shop/message/sms");
}
</script>

View File

@@ -0,0 +1,61 @@
<?php
namespace addon\cases\api\controller;
use app\api\controller\BaseApi;
use addon\cases\model\Cases as CasesModel;
use app\model\shop\Shop as ShopModel;
/**
* 电子名片
*/
class Cases extends BaseApi
{
/**
* 名片数据
*/
public function cases()
{
$shop_model = new ShopModel();
$list = model('cases')->getList(['site_id'=>$this->site_id],'*','displayorder desc');
$shop_info_result = $shop_model->getShopInfo(['site_id'=>$this->site_id])['data'];//$this->site_id
$Casesmodel = new CasesModel();
$set = $Casesmodel->getCasesSet($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
//视频文件
$video_list = model('cases_video')->getList(['site_id'=>$this->site_id],'*','createtime desc');
//企业文件
$file_list = model('cases_files')->getList(['site_id'=>$this->site_id],'*','createtime desc');
//电子名片diy
// $config = $Casesmodel->getCasesSet($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
// $config['value'] = json_decode($config['value'],true);
return $this->response(['code'=>'0','data'=>$list,'message'=>'操作成功','shop'=>$shop_info_result,'set'=>$set,'video_list'=>$video_list,'file_list'=>$file_list]);
}
public function getPersonnelset(){
$Casesmodel = new CasesModel();
$config = $Casesmodel->getCasesSet($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
$this->response($config);
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [],
// 自定义页面路径
'link' => [
[
'name' => 'CASES_INFO',
'title' => '案例展示',
'parent' => 'BASICS_LINK',
'wap_url' => '/pages_tool/cases/index',
'web_url' => '',
'sort' => 0
]
],
// 自定义图标库
'icon_library' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [],
// uni-app 页面,多个逗号隔开
'pages' => [],
// 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
];

View File

@@ -0,0 +1,18 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
//展示活动
'ShowPromotion' => [
'addon\cases\event\ShowPromotion',
],
],
'subscribe' => [
],
];

View File

@@ -0,0 +1,21 @@
<?php
/**
*/
return [
'name' => 'cases',
'title' => '案例展示',
'description' => '展示案例信息',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1.0.0',
'version_no' => '2025051923121',
'content' => '',
];

View File

@@ -0,0 +1,201 @@
<?php
// +----------------------------------------------------------------------
// | 店铺端菜单设置
// +----------------------------------------------------------------------
return [
[
'name' => 'CASES_ROOT',
'title' => '案例展示',
'url' => 'cases://shop/cases/lists',
'parent' => 'PROMOTION_TOOL',
'picture' => 'addon/cases/shop/view/public/img/live_new.png',
'picture_selected' => 'addon/cases/shop/view/public/img/live_select.png',
'is_show' => 1,
'sort' => 100,
'child_list' => [
[
'name' => 'CASES_LIST',
'title' => '人员列表',
'url' => 'cases://shop/cases/lists',
'is_show' => 1,
'sort' => 1,
'child_list' => [
[
'name' => 'CASES_ADD',
'title' => '添加人员',
'url' => 'cases://shop/cases/add',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
[
'name' => 'CASES_EDIT',
'title' => '编辑人员',
'url' => 'cases://shop/cases/edit',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
[
'name' => 'CASES_DELETE',
'title' => '删除人员',
'url' => 'cases://shop/cases/delete',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
]
],
[
'name' => 'CASES_ENTERPRISE_LIST',
'title' => '企业文件',
'url' => 'cases://shop/enterprise/lists',
'is_show' => 1,
'sort' => 2,
'child_list' => [
[
'name' => 'CASES_ENTERPRISE_ADD',
'title' => '添加企业文件',
'url' => 'cases://shop/enterprise/add',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
[
'name' => 'CASES_ENTERPRISE_EDIT',
'title' => '编辑企业文件',
'url' => 'cases://shop/enterprise/edit',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
[
'name' => 'CASES_ENTERPRISE_DELETE',
'title' => '删除企业文件',
'url' => 'cases://shop/enterprise/delete',
'sort' => 2,
'is_show' => 0,
'is_control' => 1,
],
]
],
[
'name' => 'CASES_VIDEO_LIST',
'title' => '视频文件',
'url' => 'cases://shop/enterprise/videolists',
'is_show' => 1,
'sort' => 3,
'child_list' => [
[
'name' => 'CASES_VIDEO_ADD',
'title' => '添加视频文件',
'url' => 'cases://shop/enterprise/videoadd',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
[
'name' => 'CASES_VIDEO_EDIT',
'title' => '编辑视频文件',
'url' => 'cases://shop/enterprise/videoedit',
'sort' => 1,
'is_show' => 0,
'is_control' => 1,
],
[
'name' => 'CASES_VIDEO_DELETE',
'title' => '删除视频文件',
'url' => 'cases://shop/enterprise/videodelete',
'sort' => 2,
'is_show' => 0,
'is_control' => 1,
],
]
],
// [
// 'name' => 'MESSAGE_ROOT',
// 'title' => '留言列表',
// 'url' => 'cases://shop/cases/message',
// 'is_show' => 1,
// 'sort' => 4,
// 'child_list' => [
// ],
// ],
// [
// 'name' => 'CONTACT_SHOW',
// 'title' => '电子名片',
// 'url' => 'cases://shop/cases/diy',
// 'is_show' => 1,
// 'sort' => 5,
// 'child_list' => [
// ],
// ],
[
'name' => 'CASES_SET',
'title' => '设置',
'url' => 'cases://shop/cases/set',
'is_show' => 1,
'sort' => 6,
'child_list' => [
],
],
// [
// 'name' => 'CASES_SET',
// 'title' => '基础设置',
// 'url' => 'cases://shop/cases/set',
// 'is_show' => 1,
// 'sort' => 3,
// 'child_list' => [
// ],
// ]
]
],
];
// +----------------------------------------------------------------------
// | 平台端菜单设置
// +----------------------------------------------------------------------
/*
return [
[
'name' => 'CASES_ROOT',
'title' => '电子名片',
'url' => 'cases://shop/cases/lists',
'picture' => 'addon/cases/shop/view/public/img/live_new.png',
'picture_selected' => 'addon/cases/shop/view/public/img/live_select.png',
'parent' => 'CASES_TOOL',
'is_show' => 1,
'sort' => 1,
'child_list' => [
[
'child_list' => [
]
],
]
],[
'name' => 'MESSAGE_ROOT',
'title' => '留言列表',
'url' => 'cases://shop/cases/message',
'parent' => 'CASES_TOOL',
'is_show' => 1,
'picture' => '',
'picture_select' => '',
'sort' => 1,
'child_list' => [],
],
];
*/

View File

@@ -0,0 +1 @@
SET NAMES 'utf8';

View File

@@ -0,0 +1 @@
SET NAMES 'utf8';

View File

@@ -0,0 +1,25 @@
<?php
/**
*/
namespace addon\cases\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace addon\cases\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'cases',
//店铺端展示分类 shop:营销活动 member:互动营销
'show_type' => 'tool',
//展示主题
'title' => '案例展示',
//展示介绍
'description' => '展示案例信息',
//展示图标
'icon' => 'addon/cases/icon.png',
//跳转链接
'url' => 'cases://shop/cases/lists',
]
]
];
return $data;
}
}

Some files were not shown because too many files have changed in this diff Show More