Post 如何修改我的HTTP.call(),使其返回相关信息?
下面的HTTP.call()代码返回不需要的胡言乱语。 下面是HTTP.call()代码: 理想的回报应该类似于:Post 如何修改我的HTTP.call(),使其返回相关信息?,post,meteor,xmlhttprequest,Post,Meteor,Xmlhttprequest,下面的HTTP.call()代码返回不需要的胡言乱语。 下面是HTTP.call()代码: 理想的回报应该类似于: The payment of KES 222 has been sent your account 但我在候机楼里听到了这样的胡言乱语: I20170712-21:18:51.366(3)? { statusCode: 200, I20170712-21:18:51.368(3)? content: '<br />\n<b>Notice</b&g
The payment of KES 222 has been sent your account
但我在候机楼里听到了这样的胡言乱语:
I20170712-21:18:51.366(3)? { statusCode: 200,
I20170712-21:18:51.368(3)? content: '<br />\n<b>Notice</b>: Undefined index: recipient in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>19</b> <br />\n<br />\n<b>Notice</b>: Undefined index: amount in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>21</b> <br />\n<br />\n<b>Notice</b>: Undefined index: payer in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>26</b> <br />\n<br />\n<b>Notice</b>: Undefined index: amount in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>28</b> <br />\nReceived error response: The request content was malformed:\nExpected String as JsString, but got null',
I20170712-21:18:51.368(3)? headers:
I20170712-21:18:51.369(3)? { date: 'Wed, 12 Jul 2017 18:18:49 GMT',
I20170712-21:18:51.370(3)? server: 'Apache/2.4.18 (Unix) OpenSSL/1.0.2g PHP/5.6.20 mod_perl/2.0.8-dev Perl/v5.16.3',
I20170712-21:18:51.371(3)? 'x-powered-by': 'PHP/5.6.20',
I20170712-21:18:51.371(3)? 'content-length': '619',
I20170712-21:18:51.372(3)? connection: 'close',
I20170712-21:18:51.373(3)? 'content-type': 'text/html; charset=UTF-8' },
I20170712-21:18:51.376(3)? data: null }
I20170712-21:18:51.400(3)? Exception in callback of async function: ReferenceError: msg is not defined
I20170712-21:18:51.401(3)? at server/main.js:39:33
I20170712-21:18:51.402(3)? at runWithEnvironment (packages/meteor.js:1176:24)
请帮助我解释如何修改HTTP.call(),使其返回相关信息。对我来说,“胡言乱语”看起来像一条错误消息。难道你根本没有分析过吗?
msg没有定义
;)@Sindis谢谢,但是你能详细说明我应该如何修改代码以只接收消息吗?@SirBT在下面的行中,它写着:server/main.js:39:33
,所以main.js的第39行中可能有未定义的msg
字段file@JamesZ我知道这是个错误信息,但我恳请您就如何修改代码以使我能够阅读存储在$msg中的消息提供建议。你对如何做到这一点有什么想法吗?
I20170712-21:18:51.366(3)? { statusCode: 200,
I20170712-21:18:51.368(3)? content: '<br />\n<b>Notice</b>: Undefined index: recipient in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>19</b> <br />\n<br />\n<b>Notice</b>: Undefined index: amount in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>21</b> <br />\n<br />\n<b>Notice</b>: Undefined index: payer in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>26</b> <br />\n<br />\n<b>Notice</b>: Undefined index: amount in <b>/opt/lampp/htdocs/AfricasTalking/escrow/c2b.php</b> on line <b>28</b> <br />\nReceived error response: The request content was malformed:\nExpected String as JsString, but got null',
I20170712-21:18:51.368(3)? headers:
I20170712-21:18:51.369(3)? { date: 'Wed, 12 Jul 2017 18:18:49 GMT',
I20170712-21:18:51.370(3)? server: 'Apache/2.4.18 (Unix) OpenSSL/1.0.2g PHP/5.6.20 mod_perl/2.0.8-dev Perl/v5.16.3',
I20170712-21:18:51.371(3)? 'x-powered-by': 'PHP/5.6.20',
I20170712-21:18:51.371(3)? 'content-length': '619',
I20170712-21:18:51.372(3)? connection: 'close',
I20170712-21:18:51.373(3)? 'content-type': 'text/html; charset=UTF-8' },
I20170712-21:18:51.376(3)? data: null }
I20170712-21:18:51.400(3)? Exception in callback of async function: ReferenceError: msg is not defined
I20170712-21:18:51.401(3)? at server/main.js:39:33
I20170712-21:18:51.402(3)? at runWithEnvironment (packages/meteor.js:1176:24)
<?php
require_once "AConnect.php";
//Specify your credentials
$username = "007";
$apiKey = "AC6ea8e1541e7ee0c40915e";
// NOTE: If connecting to the sandbox, please use your sandbox login credentials
//Create an instance of our awesome gateway class and pass your credentials
$gateway = new AConnect($username, $apiKey, "sandbox");
// Specify the name of your AConnect payment product
$productName = "cente";
// The 3-Letter ISO currency code for the checkout amount
// Provide the details of a mobile money recipient
$recipient = array(
"phoneNumber" => $_POST['recipient'],
"currencyCode" => "KES",
"amount" => $_POST['amount'],
"metadata" => array(
"name" => "Something...",
"reason" => "Som other thing...")
);
$phoneNumber = $_POST['payer'];
$currencyCode = "KES";
$amount = $_POST['amount'];
$metadata = array("name" => "Something...", "reason" => "Som other thing...");
try {
$transactionId = $gateway->initiateMobilePaymentCheckout($productName,
$phoneNumber,
$currencyCode,
$amount,
$metadata);
$msg = 'The payment of '. $currencyCode .' '. $amount .' has been sent your account';
$gateway->sendMessage($_POST['recipient'].','.$_POST['payer'], $msg);
echo $msg;
} catch(AConnect $e){
echo "Received error response: ".$e->getMessage();
}
?>
Meteor.methods({
'c2b': function(recipientsNumber, recipientsAmount, payer){
var postData = {
params: {
"payer": payer,
"recipient": recipientsNumber,
"amount": recipientsAmount
}
}
HTTP.call('POST', 'http://2117c3a8.ngrok.io/AConnect/c2b.php',
{ headers: { apiKey: 'AC6ea8e1541e7ee0c40915e' }, params: postData},
function(error, response) {
if (error) {
console.log(error);
}
if (response) {
console.log(response);
}
}
);
}
});