我正在尝试使用wap = box kannel发送wap。我所指的例子http://www.kannel.org/pipermail/users/2011-September/016716.html
替换时收到错误。
无法找出错误的位置。
kannel错误。
2014-03-06 12:00:06 [25702] [14] WARNING: PPG: pap control entity erroneous, the request unacceptable
<?xml version="1.0"?><!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN" "http://www.wapforum.org/DTD/pap_1.0.dtd"><pap><badmessage-response code="2000" desc="Not understood due to malformed syntax" bad-message-fragment="<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP1.0//EN"
"http://www.wapforum.org/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="71417">
<address address-value="WAPPUSH=+919971132145/TYPE=PLMN at ppg.nokia.com"/>
<quality-of-service delivery-method="unconfirmed" network-required="true" network="GSM" bearer-required="true" bearer="SMS"/>
</push-message>
</pap>"></badmessage-response></pap>
我的PHP代码是:
<?php
$country_code = '91';
$phone = '9971132145';
$push_url = "http://m.yahoo.com";
$text = 'Test yahoo wap';
$smsc_id = 'TEST-WAP';
$out = send_wap_push($smsc_id, $country_code, $phone, $push_url, $text);
echo $out;
function send_wap_push($smsc_id, $country_code, $phone, $push_url,$text)
{
$host = '127.0.0.1';
$port = '10166';
$url = "http://$host:$port";
$ppg_user = 'userid';
$ppg_pass = 'pwd';
$wap_push_id = get_rand_numbers(5);
$body = "--multipart-boundary\r\n".
"Content-type: application/xml\r\n\r\n".
'<?xml version="1.0"?>'."\r\n".
'<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP1.0//EN"'."\r\n".
'"http://www.wapforum.org/DTD/pap_1.0.dtd">'."\r\n".
'<pap>'."\r\n".'<push-message push-id="'.$wap_push_id.'">'."\r\n\t".
'<address address-value="WAPPUSH=+'.$country_code.$phone.'/TYPE=PLMN at ppg.nokia.com"/>'."\r\n\t".
'<quality-of-service delivery-method="unconfirmed" network-required="true" network="GSM" bearer-required="true" bearer="SMS"/>'."\r\n</push-message>\r\n"."</pap>\r\n\r\n"."--multipart-boundary\r\n"."Content-type: text/vnd.wap.si\r\n\r\n".
'<?xml version="1.0"?>'."\r\n".
'<!DOCTYPE si PUBLIC "-//WAPFORUM//DTD SI 1.0//EN"'."\r\n".
'"http://www.wapforum.org/DTD/si.dtd">'."\r\n"."<si>\r\n".
'<indication action="signal-high" si-id="'.$wap_push_id.'" href="'.$push_url .'">'.$text.'</indication>'."\r\n"."</si>\r\n"."--multipart-boundary--\r\n";
$post = "POST /cgi-bin/wap-push.cgi?username=msgbroker&password=msgbroker HTTP/1.1\r\n".
"Host: $host:$port\r\n".
"Authorization: Basic ".base64_encode("$ppg_user:$ppg_pass")."\r\n".
"X-Kannel-SMSC: $smsc_id\r\n".'Content-Type: multipart/related;boundary=multipart-boundary;type="application/xml"'."\r\n".
"Content-Length: ".strlen($body)."\r\n"."\r\n". $body;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt ($ch,CURLOPT_CUSTOMREQUEST , $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$reply = curl_exec($ch);
curl_close ($ch);
return $reply;
//print_r($post.$body);
}
function assign_rand_value($num)
{
// accepts 1 - 36
switch($num)
{
case "1":
$rand_value = "a";
break;
case "2":
$rand_value = "b";
break;
case "3":
$rand_value = "c";
break;
case "4":
$rand_value = "d";
break;
case "5":
$rand_value = "e";
break;
case "6":
$rand_value = "f";
break;
case "7":
$rand_value = "g";
break;
case "8":
$rand_value = "h";
break;
case "9":
$rand_value = "i";
break;
case "10":
$rand_value = "j";
break;
case "11":
$rand_value = "k";
break;
case "12":
$rand_value = "l";
break;
case "13":
$rand_value = "m";
break;
case "14":
$rand_value = "n";
break;
case "15":
$rand_value = "o";
break;
case "16":
$rand_value = "p";
break;
case "17":
$rand_value = "q";
break;
case "18":
$rand_value = "r";
break;
case "19":
$rand_value = "s";
break;
case "20":
$rand_value = "t";
break;
case "21":
$rand_value = "u";
break;
case "22":
$rand_value = "v";
break;
case "23":
$rand_value = "w";
break;
case "24":
$rand_value = "x";
break;
case "25":
$rand_value = "y";
break;
case "26":
$rand_value = "z";
break;
case "27":
$rand_value = "0";
break;
case "28":
$rand_value = "1";
break;
case "29":
$rand_value = "2";
break;
case "30":
$rand_value = "3";
break;
case "31":
$rand_value = "4";
break;
case "32":
$rand_value = "5";
break;
case "33":
$rand_value = "6";
break;
case "34":
$rand_value = "7";
break;
case "35":
$rand_value = "8";
break;
case "36":
$rand_value = "9";
break;
}
return $rand_value;
}
function get_rand_numbers($length)
{
if($length>0)
{
$rand_id="";
for($i=1; $i<=$length; $i++)
{
mt_srand((double)microtime() * 1000000);
$num = mt_rand(27,36);
$rand_id .= assign_rand_value($num);
}
}
return $rand_id;
}
?>
执行此代码后完成响应:
HTTP/1.1 202 Accepted
Server: Kannel/svn-runknown
Date: Thu, 06 Mar 2014 07:02:03 GMT
Content-Length: 786
Content-Type: application/xml
<?xml version="1.0"?><!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN" "http://www.wapforum.org/DTD/pap_1.0.dtd"><pap><badmessage-response code="2000" desc="Not understood due to malformed syntax" bad-message-fragment="<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP1.0//EN"
"http://www.wapforum.org/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="24502">
<address address-value="WAPPUSH=+919971132145/TYPE=PLMN at ppg.nokia.com"/>
<quality-of-service delivery-method="unconfirmed" network-required="true" network="GSM" bearer-required="true" bearer="SMS"/>
</push-message>
</pap>"></badmessage-response></pap>
Kannel configuraiton文件:
group = core
admin-port = 10162
smsbox-port = 10163
wapbox-port = 10164
admin-password = xs197
wdp-interface-name = "*"
status-password = xs198
admin-deny-ip = "*.*.*.*"
admin-allow-ip = "127.0.0.1;10.2.96.71"
log-file = "./1234-kannel.log"
log-level = 1
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"
access-log = "./kannel-access.log"
sms-resend-retry=0
sms-outgoing-queue-limit=2500000
sms-incoming-queue-limit= -1
# SMSC CONNECTIONS
group = smsc
smsc = smpp
smsc-id = TEST-WAP
host=*.*.*.*
port=4321
transceiver-mode = false
smsc-username = "*****"
smsc-password = "*****"
system-type = ""
enquire-link-interval = 30
throughput = 2
interface-version = 34
source-addr-ton = 5
source-addr-npi = 0
source-addr-autodetect = no
dest-addr-ton = 1
dest-addr-npi = 1
max-pending-submits=1000
wait-ack=10
wait-ack-expire=0x00
# SMSBOX SETUP
group = smsbox
bearerbox-host = localhost
sendsms-port = 10165
log-file = "./smsbox.log"
log-level = 3
access-log = "./smsaccess.log"
reply-requestfailed = "Sorry, your request failed, Please try again!"
group = wapbox
bearerbox-host = localhost
log-file = "./wap_log.log"
log-level = 0
syslog-level = none
group = ppg
ppg-url = /cgi-bin/wap-push.cgi
ppg-port = 10166
concurrent-pushes = 100
trusted-pi = false
users = 1024
ppg-allow-ip = "*.*.*.*"
# PPG USER SETUP, for authorizing a specific push user
group = wap-push-user
wap-push-user = wapuser
ppg-username = userid
ppg-password = pwd
# SERVICES
group = sms-service
keyword = default
get-url = "http://*.*.*.*/123470.php?cli=%p&content=%a&shortcode=%P"
max-messages=5
concatenation = true
# Default service - I will make this to be something like - This should return a blank message
group = sendsms-user
username = userid
password = pwd
user-deny-ip = "*.*.*.*"
user-allow-ip = "127.0.0.1"
max-messages = 5
#split-chars="*"
concatenation = true