Đối với người dùng requeriments các backend phải PHP và khách hàng ứng dụng được trong Ionic 2. Căn cứ vào:Đăng ký doanh nghiệp trong Notification Hub với PHP Backend
https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx https://github.com/Azure/azure-notificationhubs-samples/tree/master/notificationhubs-rest-php https://github.com/webwarejp/notificationhubs-rest-php
Create Registration Notification Hub Azure PHPquan trọng
Tôi đã tạo phương pháp này trong API php:
$uri = $this->endpoint . $this->hubPath . "/registrations".NotificationHub::API_VERSION;
/* print($uri); */
$ch = curl_init($uri);
$token = $this->generateSasToken($uri);
$headers = [
'Authorization: '. $token,
'Content-Type: '."application/atom+xml;type=entry;charset=utf-8",
'x-ms-version: 2015-01',
'Content-Length: 0'
];
$body = $this->getXmlAndroid($registrationId, $tag);
print_r($body);
curl_setopt_array($ch, array(
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $body
));
$response = curl_exec($ch);
// Check for errors
if($response === FALSE){
print_r(curl_error($ch));
throw new Exception(curl_error($ch));
}
$info = curl_getinfo($ch);
print_r($info);
curl_close($ch);
Phương pháp getXmlAndroid là đơn giản định dạng xml trở lại với GCM ID
private function getXmlAndroid($registrationId){
return '<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<GcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<GcmRegistrationId>'.$registrationId.'</GcmRegistrationId>
</GcmRegistrationDescription>
</content>
</entry>';
}
tôi nhận được GcmRegistrationId với chức năng này trong Ionic 2 ứng dụng.
import { Push, PushObject, PushOptions } from '@ionic-native/push';
....
const options: PushOptions = {
android: { senderID: 'MyIDFirebaseProject'},
ios: { alert: 'true', badge: true, sound: 'false'},
windows: {}
};
pushObject.on('registration').subscribe((registration: any) => {
console.log(registration.registrationId);
});
Vấn đề là luôn luôn yêu cầu Hình thức đăng ký trong thông báo lợi nhuận API
[http_code] => 400
đâu 400 có nghĩa là "cơ thể không hợp lệ theo yêu cầu. Việc đăng ký không thể được tạo ra bởi vì các yêu cầu đã bị thay đổi." . Tôi không hiểu tại sao điều này lại xảy ra.
Vâng đây là vấn đề ngu ngốc, tiêu đề này là không cần thiết. – CampDev