Home >Backend Development >PHP Tutorial >请教关于百度云推送的问题(急)
最近在做百度云推送接口的问题,出现了些问题
代码如下:
//推送ios设备消息 function test_pushMessage_ios ($user_id,$channel_id,$title,$badge,$receivemobile,$caseid,$msgid) { $appid = $this->appid; $apiKey = $this->apiKey; $secretKey= $this->secretKey; //$this->initPUSH(); $channel = new Channel ( $apiKey, $secretKey ) ; /* $push_type * 1:单个人,必须指定user_id 和 channel_id (指定设备上的指定用户)或者user_id(指定用户的所有设备) * 2:一群人,必须指定 tag_name * 3:所有人,无须指定tag_name、user_id、channel_id */ $push_type = 1; //推送单播消息 $optional[Channel::USER_ID] = $user_id; //如果推送单播消息,需要指定user // $optional[Channel::CHANNEL_ID] = $channel_id ; //如果推送单播消息,需要指定user $optional[Channel::DEVICE_TYPE] = 4;//指定发到ios设备 $optional[Channel::MESSAGE_TYPE] = 1; //指定消息类型为通知 //如果ios应用当前部署状态为开发状态,指定DEPLOY_STATUS为1,默认是生产状态,值为2. 旧版本曾采用不同的域名区分部署状态,仍然支持。 $optional[Channel::DEPLOY_STATUS] = 2; //通知类型的内容必须按指定内容发送,示例如下: $message = '{ "aps":{ "alert":"'.$title.'", "sound":"", "badge":'.$badge.' }, "receivemobile":"'.$receivemobile.'", "caseid":"'.$caseid.'", "msgid":"'.$msgid.'" }'; $message_key = "msg_key"; $ret = $channel->pushMessage ( $push_type, $message, $message_key, $optional ) ; //return $ret; if ( false === $ret ) { $this->error_output ( 'WRONG, ' . __FUNCTION__ . ' ERROR!!!!!' ) ; $this->error_output ( 'ERROR NUMBER: ' . $channel->errno ( ) ) ; $this->error_output ( 'ERROR MESSAGE: ' . $channel->errmsg ( ) ) ; $this->error_output ( 'REQUEST ID: ' . $channel->getRequestId ( ) ); } else { $this->right_output ( 'SUCC, ' . __FUNCTION__ . ' OK!!!!!' ) ; $this->right_output ( 'result: ' . print_r ( $ret, true ) ) ; }
$devcert="/opt/lampp/htdocs/baidu/MessageCent.pem"; $discert="/opt/lampp/htdocs/baidu/MessageCent2.pem"; $cert_name="test"; $cert_des="test"; $cert_name="test"; $cert_des="test"; $fd = fopen($devcert, 'r'); $devcert = fread($fd, filesize($devcert)); // 开发版APNs pem证书 $fd = fopen($discert, 'r'); $discert = fread($fd, filesize($discert)); // 发布版APNs pem证书 //print_r($discert); $ret = $channel->initAppIoscert($cert_name, $cert_des, $discert, $devcert); // cert_name和cert_des您自定义字符串即可
生产环节下,推送单播消息,提示
[1;40;32mSUCC, test_pushMessage_ios OK!!!!![0m [1;40;32mresult: Array ( [request_id] => 2197319330 [response_params] => Array ( [success_amount] => 0 [msgids] => Array ( ) ) ) [0m
如果生产模式下,群推,提示
[1;40;32mSUCC, test_pushMessage_ios OK!!!!![0m [1;40;32mresult: Array ( [request_id] => 2196426378 [response_params] => Array ( [success_amount] => 1 [resource_ids] => Array ( [0] => msgid#5305396010453184756 ) ) ) [0m
楼主解决了吗?告知一下,谢谢!