Skip to content

Commit

Permalink
Merge pull request #4 from ztbcms/aliyun
Browse files Browse the repository at this point in the history
新增阿里云短信服务
  • Loading branch information
Jayin authored Sep 14, 2017
2 parents 6e5cb5b + 4f8a3d9 commit f1d816c
Show file tree
Hide file tree
Showing 1,295 changed files with 117,939 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Install/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
//状态,1是显示,0不显示(需要参数的,建议不显示,例如编辑,删除等操作)
"status" => 1,
//名称
"name" => "短信模块",
"name" => "短信",
//备注
"remark" => "短信模块",
"remark" => "短信模块",
//子菜单列表
"child" => array(
array(
Expand Down
14 changes: 13 additions & 1 deletion Install/Sms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ CREATE TABLE `cms_sms_operator` (

INSERT INTO `cms_sms_operator` (`id`, `name`, `tablename`, `remark`, `enable`) VALUES ('1', '阿里大于', 'alidayu', '阿里大于短信平台', '1');
INSERT INTO `cms_sms_operator` (`id`, `name`, `tablename`, `remark`, `enable`) VALUES ('2', '云之讯', 'ucpaas', '云之讯短信平台', '0');
INSERT INTO `cms_sms_operator` (`id`, `name`, `tablename`, `remark`, `enable`) VALUES ('3', '阿里短信', 'alisms', '阿里短信服务', '0');
INSERT INTO `cms_sms_operator` (`id`, `name`, `tablename`, `remark`, `enable`) VALUES ('3', '阿里短信', 'alisms', '阿里消息服务之短信服务', '0');
INSERT INTO `cms_sms_operator` (`id`, `name`, `tablename`, `remark`, `enable`) VALUES ('4', '阿里云短信服务', 'aliyun', '阿里云短信服务', '0');


DROP TABLE IF EXISTS `cms_sms_alidayu`;
Expand Down Expand Up @@ -63,4 +64,15 @@ CREATE TABLE `cms_sms_alisms` (
`template` varchar(255) DEFAULT '' COMMENT '短信模版 Code',
`message_body` varchar(255) DEFAULT '' COMMENT 'SMS消息体(阿里没有说明作用,不为空即可)',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `cms_sms_aliyun`;

CREATE TABLE `cms_sms_aliyun` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`access_id` varchar(255) DEFAULT '' COMMENT 'Access Key ID(阿里云API密钥)',
`access_key` varchar(255) DEFAULT '' COMMENT 'Access Key Secret(阿里云API密钥)',
`sign` varchar(255) DEFAULT '' COMMENT '短信签名',
`template` varchar(255) DEFAULT '' COMMENT '短信模版 Code',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
79 changes: 79 additions & 0 deletions Lib/Aliyun/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* author: Jayin <[email protected]>
*/

namespace Sms\Lib\Aliyun;

//引入阿里云短信服务SDK
require_once(dirname(__FILE__) . '/vendor/autoload.php');

use Aliyun\Api\Sms\Request\V20170525\SendSmsRequest;
use Aliyun\Core\Config;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Core\Profile\DefaultProfile;
use Sms\Lib\BaseHelper;

class Helper extends BaseHelper {

/**
* 短信发送
*
* @param $conf array 配置
* @param $to string 短信接收人,多个接收人号码之间使用英文半角逗号隔开
* @param $param array 短信参数
* @return mixed
*/
function send($conf, $to, $param) {
// 加载区域结点配置
Config::load();

// 短信API产品名
$product = "Dysmsapi";

// 短信API产品域名
$domain = "dysmsapi.aliyuncs.com";

// 暂时不支持多Region
$region = "cn-hangzhou";

// 服务结点
$endPointName = "cn-hangzhou";

// 初始化用户Profile实例
$profile = DefaultProfile::getProfile($region, $conf['access_id'], $conf['access_key']);

// 增加服务结点
DefaultProfile::addEndpoint($endPointName, $region, $product, $domain);

// 初始化AcsClient用于发起请求
$acsClient = new DefaultAcsClient($profile);

// 初始化SendSmsRequest实例用于设置发送短信的参数
$request = new SendSmsRequest();

// 必填,设置雉短信接收号码
$request->setPhoneNumbers($to);

// 必填,设置签名名称
$request->setSignName($conf['sign']);

// 必填,设置模板CODE
$request->setTemplateCode($conf['template']);

// 可选,设置模板参数
if($param) {
$request->setTemplateParam(json_encode($param));
}

// 发起访问请求
$acsResponse = $acsClient->getAcsResponse($request);

// 打印请求结果
// var_dump($acsResponse);

return $acsResponse;

}
}
16 changes: 16 additions & 0 deletions Lib/Aliyun/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
27 changes: 27 additions & 0 deletions Lib/Aliyun/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "aliyuncs/aliyun-dysms-php-sdk",
"description": "Aliyun SMS SDK for PHP",
"keywords": [ "aliyun", "SMS", "sdk" ],
"type": "library",
"license": "Apache-2.0",
"homepage": "https://www.aliyun.com/product/sms",
"authors": [
{
"name": "Aliyuncs",
"homepage": "https://www.aliyun.com"
}
],
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Aliyun\\": "lib/",
"Aliyun\\Test\\": "tests/"
}
}
}
Loading

0 comments on commit f1d816c

Please sign in to comment.