我是Livecode的新手,我已经尝试了几件事将这个php http发布请求代码转换为Livecode但无法正常工作。需要使用cURL或没有cURL。
$receive_momo_request = array(
'CustomerName' => 'Customer Name',
'CustomerMsisdn'=> '054XXXX',
'CustomerEmail'=> 'customer@gmail.com',
'Channel'=> 'mtn-gh',
'Amount'=> 0.8,
'PrimaryCallbackUrl'=> 'http://requestb.in/1minotz1',
'Description'=> 'T Shirt',
);
//API Keys
$clientId = 'xxxxxxx';
$clientSecret = 'xxxxxxx';
$basic_auth_key = 'Basic ' . base64_encode($clientId . ':' . $clientSecret);
$request_url = 'https://api.hubtel.com/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney';
$receive_momo_request = json_encode($receive_momo_request);
$ch = curl_init($request_url);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $receive_momo_request);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
'Authorization: '.$basic_auth_key,
'Cache-Control: no-cache',
'Content-Type: application/json',
));
$result = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if($err){
echo $err;
}else{
echo $result;
}
到目前为止,我所做的可能是遗漏了一些东西。
on mouseUp
global gFirstName, gLastName
put gFirstName & " " & gLastName into lFullName
put lFullName into tArray[ "CustomerName"]
put "gPhoneNumber" into tArray["CustomerMsisdn"]
put "gEmail" into tArray["CustomerEmail"]
put "airtel-gh" into tArray["Channel"]
put "0.01" into tArray["Amount"]
put "http://requestb.in/1minotz1" into tArray["PrimaryCallbackUrl"]
put "FBMC Mobile" into tArray["Description"]
put true into tArray ["FeesOnCustomer"]
put ArrayToJSON(tArray) into receive_momo_request
put "ABCD" into clientId
put "1234" into clientSecret
set the httpHeaders to "Content-type: application/json" && "Authorization: Basic " && base64Encode("clientId:clientSecret") && "Cache-Control: no-cache"
post receive_momo_request to url "https://api.hubtel.com/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney"
end mouseUp
答案 0 :(得分:0)
您的LiveCode代码乍一看看起来不错。我会尝试两件事:
首先,在发布之前对您发布的数据进行URL编码。
put ArrayToJSON(tArray) into receive_momo_request
put urlEncode(receive_momo_request) into receive_momo_request
其次,在post
命令之后,检查it
变量以查看Web服务器返回的数据。您还可以检查the result
以查看是否发生了错误。
post receive_momo_request to url "https://api.hubtel.com/v1/merchantaccount/merchants/HMXXXXXXX/receive/mobilemoney"
put it into tServerFeedback
answer the result
这至少应该告诉您发出post
命令后发生的事情。