【发布时间】:2018-04-01 08:56:59
【问题描述】:
我是 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
【问题讨论】:
-
你能贴出你尝试过的代码吗?
-
我已经发布了到目前为止我尝试过的内容
-
发布任何错误或 - 您观察到它不起作用的情况会有所帮助。有错误吗?你怎么知道它不起作用?
标签: php http http-post livecode