add lguplus sms sdk

This commit is contained in:
Namhyeon Go 2019-10-08 10:24:00 +09:00
parent 91a8fd0c72
commit 7c46532d7a
10 changed files with 478 additions and 0 deletions

31
vendor/_dist/lguplus/cancel.php vendored Normal file
View File

@ -0,0 +1,31 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/cancel" );
$data = array(
"grp_id" => "DjKFPUX6VH7kCAD",
);
$msg->setData( $ch, $data );
$response = $msg->sendGet($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

27
vendor/_dist/lguplus/cash.php vendored Normal file
View File

@ -0,0 +1,27 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/cash" );
$msg->setData( $ch, null );
$response = $msg->sendGet($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

241
vendor/_dist/lguplus/openapi/message.php vendored Normal file
View File

@ -0,0 +1,241 @@
<?php
/******************************************************************************************************************************************************
작성자 : 정중배
작성일 : 2017-09-05
******************************************************************************************************************************************************/
namespace openapi;
if (!function_exists('curl_init')) {
throw new Exception('Needs the CURL PHP extension.', 301);
}
if (!function_exists('json_decode')) {
throw new Exception('Needs the JSON PHP extension.', 301);
}
class message
{
const URL = "https://openapi.sms.uplus.co.kr:4443"; // 운영환경
private $API_KEY = "";
private $API_PWD = "";
private $algorithm = 1;
private $debug = false;
/**
* 생성자
*/
public function __construct( $api_key, $pwd, $algorithm=1, $debug=false )
{
$this->API_KEY = $api_key;
$this->API_PWD = $pwd;
$this->algorithm = $algorithm;
$this->debug = $debug;
}
/*
전문 발송용 cURL 핸들 생성
*/
function getHandle( $cur_url ) {
$ch = curl_init();
// SSL 접속 설정
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 인증서 체크같은데 true 시 안되는 경우가 많다.
curl_setopt($ch, CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_2); // SSL 버젼 (https 접속시에 필요)
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // 결과값 수신여부
curl_setopt($ch, CURLOPT_URL, self::URL . $cur_url);
if($this->debug==true) echo "URL : ".self::URL.$cur_url."\r\n";
return $ch;
}
/*
전문 헤더 생성
*/
function getHeader() {
$timestamp = time(true)*1000;
$randomStr = rand(1000000000, 9999999999); // 10자리 랜덤숫자
$hmac = $this->get_hmac($timestamp, $randomStr);
$headers = array(
'charset=utf-8',
'api_key: '.$this->API_KEY,
'algorithm: '.$this->algorithm,
'hash_hmac: '.$hmac,
'cret_txt: '.$randomStr,
'timestamp: '.$timestamp,
);
if($this->debug==true) echo "getHeader()=".print_r($headers, true)."\r\n";
return $headers;
}
/*
HASH_HMAC 생성
*/
function get_hmac( $timestamp, $randomStr ) {
$sb = $this->API_KEY;
$sb .= $timestamp;
$sb .= $randomStr; // 10자리 랜덤숫자
$sb .= $this->API_PWD; // 사용자 API_KEY 비밀번호
if($this->debug==true) echo "sb = ".$sb."\n";
switch ($this->algorithm) {
case "0":
$hmac = hash( "sha256", $sb );
break;
case "1":
$hmac = sha1( $sb );
break;
case "2":
$hmac = md5( $sb );
break;
}
if($this->debug==true) echo "hmac = ".$hmac."\r\n";
return $hmac;
}
function setData( $ch, $data ) {
$headers = $this->getHeader();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->getData($data));
}
/*
multipart/form-data Request body 정보 생성
*/
function setDataFile($ch, $postfields) {
$algos = hash_algos();
$hashAlgo = null;
foreach ( array('sha1', 'md5') as $preferred ) {
if ( in_array($preferred, $algos) ) {
$hashAlgo = $preferred;
break;
}
}
if ( $hashAlgo === null ) { list($hashAlgo) = $algos; }
$boundary =
'----------------------------' .
substr(hash($hashAlgo, 'cURL-php-multiple-value-same-key-support' . microtime()), 0, 12);
$body = array();
$crlf = "\r\n";
$fields = array();
foreach ( $postfields as $key => $value ) {
if ( is_array($value) ) {
foreach ( $value as $v ) {
$fields[] = array($key, $v);
}
} else {
$fields[] = array($key, $value);
}
}
foreach ( $fields as $field ) {
list($key, $value) = $field;
if ( strpos($value, '@') === 0 ) {
preg_match('/^@(.*?)$/', $value, $matches);
list($dummy, $filename) = $matches;
$body[] = '--' . $boundary;
$body[] = 'Content-Disposition: form-data; name="' . $key . '"; filename="' . basename($filename) . '"';
$body[] = 'Content-Type: image/jpeg';
$body[] = '';
$body[] = file_get_contents($filename);
} else {
$body[] = '--' . $boundary;
$body[] = 'Content-Disposition: form-data; name="' . $key . '"';
$body[] = 'Content-Type: application/json';
$body[] = '';
$body[] = $value;
}
}
$body[] = '--' . $boundary . '--';
$body[] = '';
$content = join($crlf, $body);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
$headers = $this->getHeader();
$headers[] = 'Content-Type: multipart/form-data';
$contentLength = strlen($content);
$headers[] = 'Content-Length: ' . $contentLength;
$headers[] = 'Expect: 100-continue';
$contentType = 'boundary=' . $boundary;
// $contentType = 'multipart/form-data; boundary=' . $boundary;
$headers[] = 'Content-Type: ' . $contentType;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
/*
POST 방식으로 API를 호출한다. (발송용)
*/
function sendPost( $ch ) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$response = curl_exec($ch);
$response_header = curl_getinfo($ch);
if($this->debug==true) echo "http_code = ".$response_header["http_code"]."\n";
// if($this->debug==true) echo "response = ".$response."\n";
curl_close($ch);
return $response;
}
/*
GET 방식으로 API를 호출한다. (조회용)
*/
function sendGet( $ch ) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$response = curl_exec($ch);
$response_header = curl_getinfo($ch);
if($this->debug==true) echo "http_code = ".$response_header["http_code"]."\n";
// if($this->debug==true) echo "response = ".$response."\n";
curl_close($ch);
return $response;
}
/*
첨부파일 정보 생성
*/
function getFile( $fileName ) {
$file_name_with_full_path = realpath( $fileName );
$cFile = '@' . realpath($file_name_with_full_path);
return $cFile;
}
/*
데이터를 json 형태 string 으로 변환
*/
function getData( $data ) {
if ($data == "" || $data == null)
$str = "{}";
else {
$str = json_encode($data);
if ($str == "[]")
$str = "{}";
}
if($this->debug==true) echo "getData = ".$str."\r\n";
return $str;
}
}
?>

31
vendor/_dist/lguplus/pop.php vendored Normal file
View File

@ -0,0 +1,31 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/pop" );
$data = array(
"limit" => "100", //요청개수
);
$msg->setData( $ch, $data );
$response = $msg->sendGet($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

1
vendor/_dist/lguplus/readme.txt vendored Normal file
View File

@ -0,0 +1 @@
PHP 5 >= 5.2.0, PECL json >= 1.2.0, php-curl

39
vendor/_dist/lguplus/send.php vendored Normal file
View File

@ -0,0 +1,39 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/send" );
$data = array(
"send_type" => "S", // 발송형태(R:예약,S:즉시)
"msg_type" => "S", // SMS : S, LMS : L, MMS : M
"to" => "01011112222", // 수신자번호, ","으로 구분하여 100개까지 지정 가능하다.
"from" => "01000000000", // 발신자 번호, 발신자 번호는 사전등록된 번호여야 한다.
"subject" => "sampleTest", // LMS, MMS 의 경우, 제목을 입력할 수 있다.
"msg" => "본문 내용", // 메시지 본문 내용
"device_id" => "", // 디바이스 아이디를 지정하여 특정 디바이스를 발송제어할 수 있다.
"datetime" => "", // 예약시간(YYYYMMDDHH24MI)
"country" => "82", // 국가 코드
);
$msg->setData( $ch, $data );
$response = $msg->sendPost($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

44
vendor/_dist/lguplus/sendMMS.php vendored Normal file
View File

@ -0,0 +1,44 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/sendMMS" );
$params = array(
"send_type" => "S", // 발송형태(R:예약,S:즉시)
"msg_type" => "S", // SMS : S, LMS : L, MMS : M
"to" => "01011112222", // 수신자번호, ","으로 구분하여 100개까지 지정 가능하다.
"from" => "01000000000", // 발신자 번호, 발신자 번호는 사전등록된 번호여야 한다.
"subject" => "sampleTest", // LMS, MMS 의 경우, 제목을 입력할 수 있다.
"msg" => "본문 내용", // 메시지 본문 내용
"device_id" => "", // 디바이스 아이디를 지정하여 특정 디바이스를 발송제어할 수 있다.
"datetime" => "", // 예약시간(YYYYMMDDHH24MI)
"country" => "82", // 국가 코드
);
$data = array(
"jsonData" => $msg->getData($params),
"image" => array ( $msg->getFile("./test.jpg"), $msg->getFile("./test.jpg"), $msg->getFile("./test.jpg")),
);
$msg->setDataFile( $ch, $data );
$response = $msg->sendPost($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

32
vendor/_dist/lguplus/sent.php vendored Normal file
View File

@ -0,0 +1,32 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/sent" );
$data = array(
"grp_id" => "DjKFPUX6VH7kCAD",
"limit" => "1"
);
$msg->setData( $ch, $data );
$response = $msg->sendGet($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

32
vendor/_dist/lguplus/status.php vendored Normal file
View File

@ -0,0 +1,32 @@
<?php
require_once("./openapi/message.php");
use openapi\message;
try {
$API_KEY = "사전 등록된 API KEY";
$API_PWD = "API KEY의 비밀번호";
$msg = new message($API_KEY, $API_PWD, 1, true);
$ch = $msg->getHandle( "/v1/status" );
$data = array(
"type" => "d", // m : 월, d : 일
"send_date" => date("Ymd"), // 조회일자
);
$msg->setData( $ch, $data );
$response = $msg->sendGet($ch);
if ($response === FALSE) {
die(curl_error($ch));
}
echo "response = ".$response."\n";
} catch(Exception $e) {
echo $e->getMessage(); // get error message
echo $e->getCode(); // get error code
}
?>

BIN
vendor/_dist/lguplus/test.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB