Commit 35d606af authored by hujun's avatar hujun

推送报备信息

parent 3907f317
...@@ -11,58 +11,60 @@ namespace app\api\untils; ...@@ -11,58 +11,60 @@ namespace app\api\untils;
use think\Loader; use think\Loader;
//http的域名 define ('TL_GETUI_APPID','A8raBWQxuX9bcVmk3rkWa5');
define('HOST','http://sdk.open.api.igexin.com/apiex.htm'); define ('TL_GETUI_APPSECRET','TLNDlz8YsW6J4gexzb4AX3');
define ('TL_GETUI_APPKEY','dEC3iu81ZC9XbsVLwoiHA6');
define ('TL_GETUI_MASTERSECRET','3NNdfsgjCJ6Rmfr9l0EeI1');
define ('TL_GETUI_HOST','http://sdk.open.api.igexin.com/apiex.htm');
//define ('TL_GETUI_APPID','Cp63kT0yXMAmxVmekIQVI5');
//define ('TL_GETUI_APPSECRET','6BW6MJoIiK70mC3rJ1nK47');
//define ('TL_GETUI_APPKEY','m6kO8mg0rs85RJD1lW4Gv8');
//define ('TL_GETUI_MASTERSECRET','02DunI3DGL60rXkud74YZ8');
//define ('TL_GETUI_HOST','http://sdk.open.api.igexin.com/apiex.htm');
//定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置
define('APPKEY','m6kO8mg0rs85RJD1lW4Gv8');
define('APPID','Cp63kT0yXMAmxVmekIQVI5');
define('MASTERSECRET','02DunI3DGL60rXkud74YZ8');
class GeTuiUntils { class GeTuiUntils {
public function __construct()
{
include_once(EXTEND_PATH.'GETUI_PHP_SDK'.DS.'IGt.Push.php');
}
/** /**
* 个推 * 个推
* zhuwei *
* 2017-11-06 * @param $touchuan
* @param $black_title
* @param $content
* @return array
*/ */
function push_message_for_one() function push_message_for_one($data)
{ {
$cid = $data['device_id'];
$data=$this->request->data; $igt = new \IGeTui(TL_GETUI_HOST, TL_GETUI_APPKEY, TL_GETUI_MASTERSECRET);
//$this->changlianjie($data);
$Agentdata = $this->Agent->findById($data['agent_id']);
$cid =$Agentdata['Agent']['device_id'];
$igt = new IGeTui(TL_GETUI_HOST, TL_GETUI_APPKEY, TL_GETUI_MASTERSECRET);
//模板 //模板
$template = $this->onli_all_template($data['touchuan'], $data['black_title'],$data['content']); $template = $this->onli_all_template($data['touchuan'], $data['black_title'],$data['content']);
$this->log($data['black_title']);
//个推信息体 //个推信息体
$message = new IGtSingleMessage(); $message = new \IGtSingleMessage();
$message->set_isOffline(true); //是否离线 $message->set_isOffline(true); //是否离线
$message->set_offlineExpireTime(3600 * 12 * 1000); //离线时间 $message->set_offlineExpireTime(3600 * 12 * 1000); //离线时间
$message->set_data($template); //设置推送消息类型 $message->set_data($template); //设置推送消息类型
$message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送 $message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//接收方 //接收方
$target = new IGtTarget(); $target = new \IGtTarget();
$target->set_appId(TL_GETUI_APPID); $target->set_appId(TL_GETUI_APPID);
$target->set_clientId($cid); $target->set_clientId($cid);
//var_dump($this->request->data);
//var_dump(TL_GETUI_APPID);
//$target->set_alias(Alias);
try { try {
$rep = $igt->pushMessageToSingle($message, $target); $rep = $igt->pushMessageToSingle($message, $target);
$this->log("======pushnotice_return");
$this->log($rep);
//var_dump($rep);
echo("<br><br>");
} catch (RequestException $e) { } catch (RequestException $e) {
$requstId = $e . getRequestId(); $requstId = $e . getRequestId();
$rep = $igt->pushMessageToSingle($message, $target, $requstId); $rep = $igt->pushMessageToSingle($message, $target, $requstId);
//var_dump($rep);
echo("<br><br>");
} }
return $rep;
} }
...@@ -71,38 +73,25 @@ class GeTuiUntils { ...@@ -71,38 +73,25 @@ class GeTuiUntils {
* zhuwei * zhuwei
* 2017-11-06 * 2017-11-06
*/ */
function push_message_for_all() function push_message_for_all($data)
{ {
//Configure::write('debug', 2); $igt = new \IGeTui(TL_GETUI_HOST, TL_GETUI_APPKEY, TL_GETUI_MASTERSECRET);
$data = $this->request->data;
$igt = new IGeTui(TL_GETUI_HOST, TL_GETUI_APPKEY, TL_GETUI_MASTERSECRET);
$template = $this->onli_all_template($data['touchuan'], $data['black_title'], $data['content']); $template = $this->onli_all_template($data['touchuan'], $data['black_title'], $data['content']);
//个推信息体 //个推信息体
//基于应用消息体 //基于应用消息体
$message = new IGtAppMessage(); $message = new \IGtAppMessage();
$message->set_isOffline(true); $message->set_isOffline(true);
$message->set_offlineExpireTime(3600 * 12 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2 $message->set_offlineExpireTime(3600 * 12 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message->set_data($template); $message->set_data($template);
$message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送 $message->set_PushNetWorkType(0);//设置是否根据WIFI推送消息,1为wifi推送,0为不限制推送
//$message->set_speed(1);// 设置群推接口的推送速度,单位为条/秒,例如填写100,则为100条/秒。仅对指定应用群推接口有效。 //$message->set_speed(1);// 设置群推接口的推送速度,单位为条/秒,例如填写100,则为100条/秒。仅对指定应用群推接口有效。
$appIdList = array(TL_GETUI_APPID); $appIdList = array(TL_GETUI_APPID);
//$phoneTypeList=array($data['android_or_ios']);
//$cdt = new AppConditions();
//$cdt->addCondition(AppConditions::PHONE_TYPE, $phoneTypeList);
$message->set_appIdList($appIdList); $message->set_appIdList($appIdList);
//$message->set_conditions($cdt);
$rep = $igt->pushMessageToApp($message); $rep = $igt->pushMessageToApp($message);
//var_dump($rep); return $rep;
echo("<br><br>");
} }
/** /**
* 推送模板 * 推送模板
* zhuwei * zhuwei
...@@ -110,49 +99,19 @@ class GeTuiUntils { ...@@ -110,49 +99,19 @@ class GeTuiUntils {
*/ */
function onli_all_template($touchuan, $black_title, $content) function onli_all_template($touchuan, $black_title, $content)
{ {
//$this->changlianjie($content);
$template = new IGtTransmissionTemplate(); $template = new \IGtTransmissionTemplate();
$template->set_appId(TL_GETUI_APPID);//应用appid $template->set_appId(TL_GETUI_APPID);//应用appid
$template->set_appkey(TL_GETUI_APPKEY);//应用appkey $template->set_appkey(TL_GETUI_APPKEY);//应用appkey
$template->set_transmissionType(2);//透传消息类型 $template->set_transmissionType(2);//透传消息类型
$template->set_transmissionContent($touchuan); //透传内容 $template->set_transmissionContent($touchuan); //透传内容
//$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
/*
//如下有两个推送模版,一个简单一个高级,可以互相切换使用。此处以高级为例,所以把简单模版注释掉。
//APN简单推送
$apn = new IGtAPNPayload();
$alertmsg=new SimpleAlertMsg();
$alertmsg->alertMsg="";
$apn->alertMsg=$alertmsg;
$apn->badge=2;
$apn->sound="";
$apn->add_customMsg("payload","payload");
$apn->contentAvailable=1;
$apn->category="ACTIONABLE";
$template->set_apnInfo($apn);
//2)离线透传参数设置
//而 从 $apn = new IGtAPNPayload();这一行开始,构建的都是针对ios下app离线的推送
//其中 $alertmsg->body="body"; 对应的是在线透传的content
$alertmsg->locKey="LocKey"; 对应的是在线透传的title
$alertmsg->title="水培喝水"; 对应的也是在线透传的title
//然后 $apn->add_customMsg("payload","阿波罗度上市"); 这是用来传送自定义参数的,我们来改成我们想要的
$apn->add_customMsg("id","1");
$apn->add_customMsg("type","新闻");
*/
//APN高级推送 //APN高级推送
$apn = new IGtAPNPayload(); $apn = new \IGtAPNPayload();
$alertmsg = new DictionaryAlertMsg(); $alertmsg = new \DictionaryAlertMsg();
$alertmsg->body = $content;//对应的是在线透传的content $alertmsg->body = $content;//对应的是在线透传的content
$alertmsg->actionLocKey = "打开同联商业";//滑动打开app $alertmsg->actionLocKey = "打开同联商业";//滑动打开app
$alertmsg->locKey = $content;//锁屏提示下框 $alertmsg->locKey = $content;//锁屏提示下框
/*
$alertmsg->locArgs=array("locargs");
$alertmsg->launchImage="launchimage";
iOS8.2 支持
*/
$alertmsg->title = $black_title;//标题 锁屏标题 $alertmsg->title = $black_title;//标题 锁屏标题
$alertmsg->titleLocKey = $black_title;//下拉通知上部框框 $alertmsg->titleLocKey = $black_title;//下拉通知上部框框
$alertmsg->titleLocArgs = array("TitleLocArg"); $alertmsg->titleLocArgs = array("TitleLocArg");
...@@ -160,69 +119,63 @@ class GeTuiUntils { ...@@ -160,69 +119,63 @@ class GeTuiUntils {
$apn->alertMsg = $alertmsg; $apn->alertMsg = $alertmsg;
$apn->badge = 1;//应用icon上显示的数字 $apn->badge = 1;//应用icon上显示的数字
$apn->sound = ""; $apn->sound = "";
/*
$apn->add_customMsg("payload","阿波罗度上市");
$apn->contentAvailable=1;
$apn->category="ACTIONABLE";
*/
$template->set_apnInfo($apn); $template->set_apnInfo($apn);
return $template; return $template;
} }
/**
* 对某个人推送消息-公共
*
* zhuwei
*
* 2017-11-07 10:31:27
*/
function public_push_message_for_one($id, $device_id, $title, $content)
{
$homeurl = $this->http_host();
$data['agent_id'] =$id;
$data['black_title'] = $title;
$data['content'] = $content;
$data['device_id'] = $device_id;
$data['touchuan'] = json_encode(array(
'title' => $title,
'content' => $content,
'type' => 'other',
'url' => '',
'name' => $title,
'id' => '69',
'imageUrl' => $homeurl .'notice_android_logo.png'));
return $this->push_message_for_one($data);
}
function pushMessageToApp(){
// Loader::import('IGeTui',EXTEND_PATH.'GETUI_PHP_SDK');
include_once(EXTEND_PATH.'GETUI_PHP_SDK'.DS.'IGt.Push.php');
$igt = new \IGeTui(HOST,APPKEY,MASTERSECRET);
//定义透传模板,设置透传内容,和收到消息是否立即启动启用
$template = $this->IGtNotificationTemplateDemo();
//$template = IGtLinkTemplateDemo();
// 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)
$message = new \IGtAppMessage();
$message->set_isOffline(true);
$message->set_offlineExpireTime(10 * 60 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
$message->set_data($template);
$appIdList=array(APPID);
$phoneTypeList=array('ANDROID');
$provinceList=array('浙江');
$tagList=array('haha');
//用户属性
//$age = array("0000", "0010");
//$cdt = new \AppConditions();
// $cdt->addCondition(AppConditions::PHONE_TYPE, $phoneTypeList);
// $cdt->addCondition(AppConditions::REGION, $provinceList);
//$cdt->addCondition(AppConditions::TAG, $tagList);
//$cdt->addCondition("age", $age);
$message->set_appIdList($appIdList);
//$message->set_conditions($cdt->getCondition());
$rep = $igt->pushMessageToApp($message,"任务组名");
var_dump($rep); public function http_host()
echo ("<br><br>"); {
$http_type =
((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$host = $http_type . $_SERVER['HTTP_HOST'];
return $host;
} }
function IGtNotificationTemplateDemo(){
$template = new \IGtNotificationTemplate();
$template->set_appId(APPID); //应用appid
$template->set_appkey(APPKEY); //应用appkey
$template->set_transmissionType(1); //透传消息类型
$template->set_transmissionContent("测试离线");//透传内容
$template->set_title("个推"); //通知栏标题
// $template->set_text("个推最新版点击下载"); //通知栏内容
$template->set_text('【张三】报备了【肯德基】'); //通知栏内容
$template->set_logo(""); //通知栏logo
$template->set_logoURL(""); //通知栏logo链接
$template->set_isRing(true); //是否响铃
$template->set_isVibrate(true); //是否震动
$template->set_isClearable(true); //通知栏是否可清除
return $template;
//https请求(支持GET和POST)
function http_request($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if (curl_errno($curl)) {
return 'Errno' . curl_error($curl);
}
curl_close($curl);
return $result;
} }
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ namespace app\index\controller; ...@@ -11,6 +11,7 @@ namespace app\index\controller;
use app\api\untils\GeTuiUntils; use app\api\untils\GeTuiUntils;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\model\Agents;
use app\model\Applies; use app\model\Applies;
use app\model\AppointWatchShop; use app\model\AppointWatchShop;
use app\model\HouseInfos; use app\model\HouseInfos;
...@@ -70,7 +71,7 @@ class WatchShop extends Basic ...@@ -70,7 +71,7 @@ class WatchShop extends Basic
$appoint_watch = new AppointWatchShop(); $appoint_watch = new AppointWatchShop();
$appoint_watch->startTrans(); $appoint_watch->startTrans();
$apponit_data = $appoint_watch->get($params['watch_id'])->lock(); $apponit_data = $appoint_watch->lock(true)->where('id',$params['watch_id'])->find();
if ($apponit_data['id']) { if ($apponit_data['id']) {
$apples = new Applies(); $apples = new Applies();
...@@ -91,7 +92,7 @@ class WatchShop extends Basic ...@@ -91,7 +92,7 @@ class WatchShop extends Basic
'apply_id' => $apples->id, 'apply_id' => $apples->id,
'shopuser_id' => $params['agents_id'], 'shopuser_id' => $params['agents_id'],
'shop_id' => $params['shop_id'], 'shop_id' => $params['shop_id'],
'house_id' => $params['house_id'], 'house_id' => $apponit_data['house_id'],
'transaction_status' => 0, 'transaction_status' => 0,
'created' => date("Y-m-d H:i:s") 'created' => date("Y-m-d H:i:s")
])->save(); ])->save();
...@@ -103,8 +104,16 @@ class WatchShop extends Basic ...@@ -103,8 +104,16 @@ class WatchShop extends Basic
if ($apples->id && $remark->id) { if ($apples->id && $remark->id) {
$appoint_watch->commit(); $appoint_watch->commit();
//推送报备信息
$agent = new Agents();
$agentData = $agent->field('id,device_id,realname,agentshopname,sub_shopname')->where('id',$params['agents_id'])->find();
$title = '报备提醒';
$content = '【'.$agentData['agentshopname'].$agentData['sub_shopname']. '-' . $agentData['realname'] . '】报备了【' . $apponit_data['house_title'].'】';
$get = new GeTuiUntils();
$req = $get->public_push_message_for_one($params['agents_id'],$agentData['device_id'],$title,$content);
$data['status'] = 200; $data['status'] = 200;
$data['msg'] = '报备成功'; $data['msg'] = $req['result'] == 'ok' ? '报备成功并通知经纪人' : '报备成功,请通知经纪人';
} else { } else {
$appoint_watch->rollback(); $appoint_watch->rollback();
$data['status'] = 101; $data['status'] = 101;
...@@ -122,7 +131,11 @@ class WatchShop extends Basic ...@@ -122,7 +131,11 @@ class WatchShop extends Basic
} }
public function test(){ public function test(){
$agent = new Agents();
$agent->
$get = new GeTuiUntils(); $get = new GeTuiUntils();
$get->pushMessageToApp(); $title='报备提醒';
dump($get->public_push_message_for_one(8,'hello world','测试'));die;
} }
} }
\ No newline at end of file
...@@ -110,9 +110,14 @@ define (['doT', 'text!temp/watch_template_tpl.html', 'css!style/home.css',"datet ...@@ -110,9 +110,14 @@ define (['doT', 'text!temp/watch_template_tpl.html', 'css!style/home.css',"datet
$ (document).delegate (".add_applies", "click", function () { $ (document).delegate (".add_applies", "click", function () {
user.watch_id = $(this).attr ("data-id"); user.watch_id = $(this).attr ("data-id");
$("input[name='phone']").val('');
}); });
$ (document).delegate ("#submit_applies", "click", function () { $ (document).delegate ("#submit_applies", "click", function () {
if ($('input[name="phone"]').val() == '') {
alert('报备人信息不能为空');
return ;
}
var params = {}; var params = {};
params.shop_id = user.father_id; params.shop_id = user.father_id;
params.agents_id = user.agents_id; params.agents_id = user.agents_id;
...@@ -124,9 +129,13 @@ define (['doT', 'text!temp/watch_template_tpl.html', 'css!style/home.css',"datet ...@@ -124,9 +129,13 @@ define (['doT', 'text!temp/watch_template_tpl.html', 'css!style/home.css',"datet
data: params, data: params,
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {
if (data.code == 200) {
alert(data.msg);
$("#modal-watch").modal ('hide');
user.getList(1);
} else {
alert(data.msg); alert(data.msg);
}
} }
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment