yzms/show/push_sms.php

149 lines
5.0 KiB
PHP

<?php
ini_set("display_errors", "On");
ini_set('memory_limit', '256M');
function query($url) {
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_TIMEOUT, 30);
$s = curl_exec($c);
curl_close($c);
return $s;
}
function sendMethod($cellphone, $title, $content, $info = array(), $os = "android8") {
$post = array();
$post['Format'] = 'JSON';
$post['RegionId'] = 'cn-hangzhou';
$post['Version'] = '2016-08-01';
$post['AccessKeyId'] = 'LTAIs05FYuL9ojLR';
$post['SignatureMethod'] = 'HMAC-SHA1';
$post['Timestamp'] = date("Y-m-d\\TH:i:s\\Z", time()-3600*8);
$post['SignatureVersion'] = '1.0';
$post['SignatureNonce'] = md5(microtime()."_");
//增加处理Android8需要内容
if($os == 'android8') {
$post['DeviceType'] = 'ANDROID';
$post['PushType'] = 'NOTICE';
$post['StoreOffline'] = 'true';
$post['AndroidNotificationChannel'] = 'hxPush';
$post['AndroidPopupActivity'] = 'com.keon.ftdc.MainActivity';
$post['AndroidPopupTitle'] = $title;
$post['AndroidPopupBody'] = $content;
}
if($os == 'ios') {
$post['Action'] = 'PushNoticeToiOS';
$post['AppKey'] = '24655738';
$post['ApnsEnv'] = $_GET['DEV']?"DEV":"PRODUCT";
//$post['ApnsEnv'] = "DEV";
} elseif($os == 'android') {
$post['Action'] = 'PushNoticeToAndroid';
$post['AppKey'] = '24656233';
} elseif($os == 'android8') {
$post['Action'] = 'Push';
$post['AppKey'] = '24656233';
}
$post['Target'] = 'ACCOUNT';
$post['TargetValue'] = $cellphone;
$post['Title'] = $title;
$post['Body'] = $content;
$ExtParameters = array(
'key' => json_encode($info)
);
$post['ExtParameters'] = json_encode($ExtParameters);
ksort($post);
$qs = '';
$tosign = '';
foreach($post as $key => $v) {
if($qs != '') $qs .= "&";
if($tosign != '') $tosign .= "&";
$qs .= $key ."=" .urlencode($v);
$tosign .= rawurlencode($key) ."=" .rawurlencode($v);
}
$tosign = "GET&%2F&".rawurlencode($tosign);
//echo $tosign."\n\n";
$sign = base64_encode(hash_hmac('sha1', $tosign, "NltQrgsfhQqzrLOwmaQ6fJEAODDCbr&", true));
$qs .= "&Signature=" . urlencode($sign);
$url = "http://cloudpush.aliyuncs.com/?".$qs;
$s = query($url);
$a = json_decode($s, true);
if($a['MessageId']) return $a['MessageId'];
return false;
}
function sendTs($cellphone, $title, $content){
// $cellphone = "13630035336";
// $title = "测试";
// $content = "测试内容";
$MessageId1 = sendMethod($cellphone, $title, $content, array(''));
$MessageId2 = sendMethod($cellphone, $title, $content, array(''), 'ios');
if($MessageId1 && $MessageId2){
return true;
}else{
return false;
}
}
function sendSms($mobile, $msg)
{
//echo $msg;
//$mobile = "13392296312";
$appid = 'svcXhqBFtbvNS6GUVumSM8k0WarOLiOZ';
$appkey = 'ex1JUa3xO3JFXB9k5OqULKYYoJz7A2nV';
$msg = '【云中美食】'.$msg;
$sign = md5($appid.$mobile.$msg.$appkey);
$url = "https://sms.189ek.com/yktsms/send";
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, "appid={$appid}&mobile={$mobile}&msg=".urlencode($msg)."&sign={$sign}");
curl_setopt($c, CURLOPT_TIMEOUT, 10);
$content = curl_exec($c);
curl_close($c);
return $content;
}
//$data = $db->get_all("select a.id, b.title,b.content,c.cellphone,c.username,c.deptname,c.id as uid, b.id as notice_id from tb_notice_push a, tb_notice b, tb_user c where a.notice_id=b.id and a.user_id=c.id and a.status=0 and b.status!=0 and c.enabled not in (0, -99) and b.ispush = 1 and b.sendtime < now()");
//
//$nids = array();
//foreach($data as $item) {
// $id = $item['id'];
// $title = strip_tags($item['title']);
// $content = strip_tags($item['content']);
// $cellphone = $item['cellphone'];
// $username = $item['username'];
// $deptname = $item['deptname'];
// $uid = $item['uid'];
// $notice_id = $item['notice_id'];
// $nids[$notice_id] = 1;
// $data2 = array(
// 'notice_id' => $notice_id,
// 'user_id' => $uid,
// 'title' => $title,
// 'content' => $content,
// );
// $MessageId1 = sendTs($cellphone, $title, $content, array('type' => '1', 'data' => $data2));
// $MessageId2 = sendTs($cellphone, $title, $content, array('type' => '1', 'data' => $data2), 'ios');
// echo $MessageId1."_".$MessageId2."\n";
// $db->query("update tb_notice_push set status=1,MessageId='{$MessageId1}_{$MessageId2}' where id=".$id);
//
//}
//
//foreach($nids as $notice_id => $v) {
// $row = $db->query("select * from tb_notice_push where notice_id=".$notice_id." and status=0");
// $status = $row?2:3;
// $db->query("update tb_notice set status={$status} where id={$notice_id} and status != 0");
//}
//echo date("Y-m-d H:i:s ".count($data)."\n");