当前位置:Gxlcms > PHP教程 > 请教关于百度云推送的问题(急)

请教关于百度云推送的问题(急)

时间:2021-07-01 10:21:17 帮助过:36人阅读

最近在做百度云推送接口的问题,出现了些问题
代码如下:
//推送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 ) ) ;        }

1、之前在开发状态下,单播消息推送一直是正常的,没有任何问题,但是切换到生产状态下,推送一直失败;
2、咨询了一些人,说需要初始化证书,所以在 $channel = new Channel ( $apiKey, $secretKey ) ;之后加入了正式初始化的程序(如下程序),推送单播消息还是失败;但是这里出现了个问题是,我切换到开发状态下,单播也失败了,只有群推可以成功;
3、在百度管理控制台里,原来群推还可以收到消息,现在在管理控制台不是是开发状态还是生产状态,群推都收不到消息。

请各位帮我检查检查,看问题出现在了哪儿。

$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您自定义字符串即可


回复讨论(解决方案)

生产环节下,推送单播消息,提示
SUCC, test_pushMessage_ios OK!!!!! result: Array ( [request_id] => 2197319330 [response_params] => Array ( [success_amount] => 0 [msgids] => Array ( ) ) ) 
如果生产模式下,群推,提示
SUCC, test_pushMessage_ios OK!!!!! result: Array ( [request_id] => 2196426378 [response_params] => Array ( [success_amount] => 1 [resource_ids] => Array ( [0] => msgid#5305396010453184756 ) ) ) 

楼主解决了吗?告知一下,谢谢!

人气教程排行