mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2024-12-01 03:18:33 +08:00
消息发送
This commit is contained in:
parent
7ca13df86f
commit
14d8142479
@ -73,7 +73,7 @@ function DataReturn($msg = '', $code = 0, $data = '')
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成前台页面url地址
|
||||
* 生成接口页面url地址
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
@ -83,8 +83,24 @@ function DataReturn($msg = '', $code = 0, $data = '')
|
||||
* @param string $a [方法名称]
|
||||
* @param array $params [参数]
|
||||
*/
|
||||
function ApiUrl($c='Index', $a='Index', $params=[])
|
||||
{
|
||||
$url = U("Api/{$c}/{$a}", $params, true, true);
|
||||
$location = stripos($url, '.php');
|
||||
if($location !== false)
|
||||
{
|
||||
$before = substr($url, 0, $location+4);
|
||||
$suffix = substr($before, strrpos($before, '/')+1);
|
||||
if(!empty($suffix))
|
||||
{
|
||||
$url = str_replace($suffix, 'api.php', $url);
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成前台页面url地址
|
||||
* 生成前端页面url地址
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
@ -96,7 +112,7 @@ function DataReturn($msg = '', $code = 0, $data = '')
|
||||
*/
|
||||
function HomeUrl($c='Index', $a='Index', $params=[])
|
||||
{
|
||||
$url = U("Home/{$c}/{$a}", $params);
|
||||
$url = U("Home/{$c}/{$a}", $params, true, true);
|
||||
$location = stripos($url, '.php');
|
||||
if($location !== false)
|
||||
{
|
||||
|
@ -527,7 +527,8 @@ return array(
|
||||
0 => array('value' => 0, 'name' => '未发送'),
|
||||
1 => array('value' => 1, 'name' => '发送中'),
|
||||
2 => array('value' => 2, 'name' => '发送成功'),
|
||||
3 => array('value' => 3, 'name' => '发送失败'),
|
||||
3 => array('value' => 3, 'name' => '部分成功'),
|
||||
4 => array('value' => 4, 'name' => '发送失败'),
|
||||
),
|
||||
|
||||
|
||||
|
@ -294,6 +294,21 @@ class AlipayLife
|
||||
$this->Respond($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* [SyncRsaVerify 同步返回签名验证]
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2017-09-25T13:13:39+0800
|
||||
* @param [array] $data [返回数据]
|
||||
* @param [boolean] $key [数据key]
|
||||
*/
|
||||
private function SyncRsaVerify($data, $key)
|
||||
{
|
||||
$string = json_encode($data[$key], JSON_UNESCAPED_UNICODE);
|
||||
return $this->OutRsaVerify($string, $data['sign']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条消息发送
|
||||
* @author Devil
|
||||
@ -330,15 +345,21 @@ class AlipayLife
|
||||
// 生成签名
|
||||
$p['sign'] = $this->MyRsaSign($this->ArrayToUrlString($p));
|
||||
|
||||
// 请求接口
|
||||
$result = $this->HttpRequest('https://openapi.alipay.com/gateway.do', $p);
|
||||
|
||||
|
||||
|
||||
print_r($result);
|
||||
echo "\n\n";
|
||||
print_r($p);
|
||||
die;
|
||||
// 验证签名
|
||||
if(!$this->SyncRsaVerify($result, 'alipay_open_public_message_custom_send_response'))
|
||||
{
|
||||
return ['status'=>-1, 'msg'=>'签名验证错误'];
|
||||
}
|
||||
|
||||
// 状态
|
||||
if(isset($result['alipay_open_public_message_custom_send_response']['code']) && $result['alipay_open_public_message_custom_send_response']['code'] == 10000)
|
||||
{
|
||||
return ['status'=>0, 'msg'=>'发送成功'];
|
||||
}
|
||||
return ['status'=>-100, 'msg'=>$result['alipay_open_public_message_custom_send_response']['sub_msg'].'['.$result['alipay_open_public_message_custom_send_response']['code'].']'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -355,7 +355,7 @@ class AlipayLifeService
|
||||
*/
|
||||
public static function SyncJobSend($message_id)
|
||||
{
|
||||
SyncJob(U('Api/AlipayLife/Send', ['message_id'=>$message_id], true, true));
|
||||
SyncJob(ApiUrl('AlipayLife', 'Send', ['message_id'=>$message_id]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -371,7 +371,7 @@ class AlipayLifeService
|
||||
{
|
||||
if(empty($params['message_id']))
|
||||
{
|
||||
die('[params_time:'.date('Y-m-d H:i:s'))."][msg:id有误]\n\n";
|
||||
die('[params_time:'.date('Y-m-d H:i:s')."][msg:id有误]\n\n");
|
||||
}
|
||||
|
||||
// 启动开始
|
||||
@ -383,11 +383,11 @@ class AlipayLifeService
|
||||
$message = $m->find($params['message_id']);
|
||||
if(empty($message))
|
||||
{
|
||||
die('[time:'.date('Y-m-d H:i:s'))."][msg:{$params['message_id']}数据不存在]\n\n";
|
||||
die('[time:'.date('Y-m-d H:i:s')."][msg:{$params['message_id']}数据不存在]\n\n");
|
||||
}
|
||||
if(!in_array($message['sttaus'], [0,1]))
|
||||
if(!in_array($message['status'], [0,1]))
|
||||
{
|
||||
die('[time:'.date('Y-m-d H:i:s'))."][msg:{$message['status']}状态不可操作]\n\n";
|
||||
die('[time:'.date('Y-m-d H:i:s')."][msg:{$message['status']}状态不可操作]\n\n");
|
||||
}
|
||||
|
||||
// 消息类型
|
||||
@ -410,7 +410,7 @@ class AlipayLifeService
|
||||
// 生活号
|
||||
$life = M('AlipayLife')->find($alipay_life_id);
|
||||
|
||||
// 群发发
|
||||
// 群发
|
||||
if($message['send_type'] == 1)
|
||||
{
|
||||
die('all');
|
||||
@ -423,37 +423,35 @@ class AlipayLifeService
|
||||
$obj = new \Library\AlipayLife(['life_data'=>$life]);
|
||||
foreach($detail as $v)
|
||||
{
|
||||
// 请求接口处理
|
||||
$message['alipay_openid'] = $v['alipay_openid'];
|
||||
$obj->CustomSend($message);
|
||||
//print_r($message);
|
||||
die;
|
||||
$ret = $obj->CustomSend($message);
|
||||
|
||||
// 返回状态更新
|
||||
$status = (isset($ret['status']) && $ret['status'] == 0) ? 2 : 4;
|
||||
$detail_m->where(['id'=>$v['id']])->save(['status'=>$status, 'send_time'=>time(), 'upd_time'=>time(), 'send_return_msg'=>$ret['msg']]);
|
||||
}
|
||||
echo '[count:'.count($detail).']';
|
||||
} else {
|
||||
$m->where(['id'=>$message['id']])->save(['send_success_time'=>time(), 'status'=>2]);
|
||||
$status_all = $detail_m->where(['alipay_life_message_id'=>$message['id']])->group('status')->getField('status', true);
|
||||
if(count($status_all) <= 1)
|
||||
{
|
||||
$status = in_array(2, $status_all) ? 2 : 4;
|
||||
} else {
|
||||
$status = 3;
|
||||
}
|
||||
$m->where(['id'=>$message['id']])->save(['send_success_time'=>time(), 'status'=>$status, 'upd_time'=>time()]);
|
||||
echo '[success_time:'.date('Y-m-d H:i:s')."]\n";
|
||||
echo '[message:'.$params['message_id']."]\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
die('end');
|
||||
|
||||
// 获取详情处理发送消息
|
||||
// $detail_m = M('AlipayLifeMessageDetail');
|
||||
// $detail = $detail_m->where(['alipay_life_message_id'=>$message['id'], 'status'=>0])->limit(100)->select();
|
||||
// if(!empty($detail))
|
||||
// {
|
||||
// $obj = new \Library\AlipayLife($params);
|
||||
// foreach($detail as $v)
|
||||
// {
|
||||
// $obj->CustomSend($message);
|
||||
// print_r($message);
|
||||
// die;
|
||||
// }
|
||||
// } else {
|
||||
// $m->where(['id'=>$message['id']])->save(['send_success_time'=>time(), 'status'=>2]);
|
||||
// echo '[success_time:'.date('Y-m-d H:i:s')."]\n";
|
||||
// echo '[message:'.$params['message_id']."]\n\n";
|
||||
// }
|
||||
// 继续运行脚本
|
||||
self::SyncJobSend($message['id']);
|
||||
|
||||
// end
|
||||
die('[end_time:'.date('Y-m-d H:i:s')."][msg:处理结束]\n\n");
|
||||
}
|
||||
}
|
||||
?>
|
@ -15,10 +15,7 @@
|
||||
require './core.php';
|
||||
|
||||
// 默认绑定访问Admin模块
|
||||
if(empty($_GET['m']))
|
||||
{
|
||||
define('BIND_MODULE', 'Admin');
|
||||
}
|
||||
define('BIND_MODULE', 'Admin');
|
||||
|
||||
// 引入ThinkPHP入口文件
|
||||
require './ThinkPHP/ThinkPHP.php';
|
||||
|
@ -14,12 +14,6 @@
|
||||
// 引入公共入口文件
|
||||
require './core.php';
|
||||
|
||||
// 默认绑定访问Api模块
|
||||
if(empty($_GET['m']))
|
||||
{
|
||||
define('BIND_MODULE', 'Api');
|
||||
}
|
||||
|
||||
// 引入ThinkPHP入口文件
|
||||
require './ThinkPHP/ThinkPHP.php';
|
||||
|
||||
|
37
shopxo.sql
37
shopxo.sql
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user