-
Anharr Junior Member
 
-
Posts: 11
Threads: 5
Joined: May 2024
Reputation:
0
06-11-2024, 01:21 AM
(This post was last modified: 06-11-2024, 01:33 AM by Anharr.)
Masters, I need your help for my API Integration.
This is details step by step of my Web App :
- I will sending all of parameters (like amount billing, code bank, username, email etc) for payment to the API
This is the sample request :
$params = [
'merchantCode' => $merchantCode,
'orderType' => $orderType,
'orderNum' => $orderNum,
'pay' => $pay,
'name' => $name,
'email' => $email,
'phone' => $phone,
'notif' => $notifyUrl,
'date' => $dateTime,
'expired' => $expiryPeriod,
'sign' => $sign
];
- API will sending asynchronous response with detail is it my request is Success or not.
This is the sample of response from API :
RespCode :SUCCESS RespMessage :Request Transaction Success OrderNum :QWOIJDDJ orderNum :2024061123981 payMoney :10000 platSign :HayKQWNzo2vlKcEZ
- After receiving asynchronous notification, I need to respond to SUCCES the string to check is it my customer already paid the billing or not.
This is the sample of code :
$res = json_decode(file_get_contents('php://input'), true);$platSign = $res['platSign'];unset($res['platSign']);
Because I need to check my customers already paid the billing or not. So, My question is :
How to sending all of API response before, using json_decode(file_get_contents('php://input), true);
I'm so sorry if my English is bad, if you confused with my question please let me know.
-
Anharr Junior Member
 
-
Posts: 11
Threads: 5
Joined: May 2024
Reputation:
0
06-11-2024, 01:50 AM
(This post was last modified: 06-11-2024, 01:53 AM by Anharr.)
(06-11-2024, 01:29 AM)ozornick Wrote: What kind of response is expected by the payment system?
They expect is to sending response SUCCESS using
$res = json_decode(file_get_contents('php://input'), true);
after that, create new variable and get value from 'platSign' parameters.
Example :
$res = json_decode(file_get_contents('php://input'), true);
$platSign = $res['platSign'];
unset($res['platSign']);
//Decrypt Sign
$decrypt = $this->Encrypt->public_key_decrypt($platSign, $myOwnPublicKey);
-
badger Member
  
-
Posts: 84
Threads: 22
Joined: Apr 2015
Reputation:
2
I don't know if this is what you're looking for but it might help. I'm only an amateur but I'm doing something similar with sage accounting and it looks like below. apihandler_perform sends a request to sage using oauthClient. The oauthClient response is then returned from apihandler_perform which is then sent back to whatever it was that called process_invoice(). In my case the 2fa token expires after 3 minutes so before my api handler sends data to sage, it checks if the token is valid and renews it if not and then sends the data.
Bill
PHP Code: public function process_invoice(){ try { $data = json_decode(file_get_contents('php://input')); $sage_id=$this->apihandler_perform('invoices','get',$data); $this->sendResponse(['sage_id'=>$sage_id]); } catch (Exception $e){ $this->sendResponse(['error'=>$e->getMessage()]); } } public function sendResponse($result, $httpcode = 200): void { $result = json_encode($result); header('HTTP/1.1: '.$httpcode); header('Status: '.$httpcode); header('Content-Length: ' . strlen($result)); header('Content-type: ' . 'application/json'); echo $result; }
-
InsiteFX Super Moderator
     
-
Posts: 6,798
Threads: 348
Joined: Oct 2014
Reputation:
248
This is the sample code that they are using.
PHP Code: <?php
// 平台公钥,从密钥配置中获取 // platform public key, from Secret key config $platPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiaKBgQCcEUIvQ/5L+SWbHOeR8VFeZvLbUk7V7OeEAQlQwIVLSZMTef3KtsOKKAsUYPf/aAcKRzZZXECODsPQiDPcdZvM/rFkgrFWkR7lPjTj5SiPxGaiK2Z2sne7A8aDF7fV/D7lfmEwNdZ7FWKVEB84/81BHnlGUwb5HpRTISG+boSO6wIDAQAB';
// 商户私钥,商户自己生成 // mchchant private key $mchPrivateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMigm7rtWnTeNagwFzGTH+Uw1ypbiy7VhIoFJbgSYSSHdCaXWdT/l2+2fQlEYgAETVZ/IXB29MCnrf3O0dwRFXiipIbsm5zyqSLiS6cKXe8zN1/PlQWUbEt5wyWm0GADB/4bV6eu6gA7sGXmjQqrzfKZkcie3aK7+7ry1NFxTI51AgMBAAECgYEAklqXQAVlt1tiSQ7L3J425jp6u6uMHN4lkYmvuleuBbfKQ1yla3wIPLYjAF+iHeEFidOz0Rb19JRdmIkHDkJoJg2W27LvO6RdUwzgRnsuA3OuNz97w08B3aXXbPmB91nTFjKSlUsbh3IQWP71noxW+iKn844EW5hC5Gvn4L3quAECQQDrz1r0VKIbBSBB2aLuz1XyD/TBT2aRhvOKf0XtTRiQhNjtJxoQmvNbbhvUwj8an7HyCuihAbdbrC2ymFFyOSDZAkEA2c4Yudi48C6COrroi1cWgPlEFeGJXP/V1k5loZ1n2vstYAGPhAB4wUnFBLDvMqaBzWJt7MRkiazT8KnBQCDY/QJAMXpNlEyZwt+deBOpO0BnwSWV7mWxmMFfImU4D+WITPbC7aexsWBBxaJh1o93XCe715RwYTAR//stj3akSDoyaQJAa4FKuxC51/Nc3Fg9R+modeiTLqmv/3NXvPvdNjRXesLX1rduex0wfVdII9ShfEKrdxDKaT9W0NyzD+r6NAkCkQJBAMAnTgPYf0f7rh417GdoP7R7Nwi8KBKwPHlmfRukibOQlKt9xjqpsKJwglLn8pcnXbYbswXIdqzuBvIGAe3OWNg=';
// 商户ID,从商户信息中获取 // merchent ID from idntask, from User info $merchantCode = 'YOUR MERCHANT ID';
// 商户用户ID $mchUserIid = '100001';
// 支付金额 pay money(最大支持6位小数) $payMoney = '1.000001';
// 支付方式 参考: (USDT/BTC/ETH/TRX) $method = 'USDT';
//订单类型(0-法币交易,1-数字货币交易) $orderType = '1';
// 商户订单号(有单模式必传,无单模式不传) $orderNum = 'T'.date("YmdHis",time());
//时间戳 格式 yyyyMMddHHmmss $dateTime = date("YmdHis",time());
// 邮箱(Customer's email address) $email = '[email protected]';
// 手机号码(Customer's mobile number) $phone = '082112345678';
// 在付款确认页面显示的转账对象(Display name on bank confirmation display) $name = 'Neo';
// 回调地址(notify url) $notifyUrl = 'http://example.com/callback';
// 订单过期时间 Order expiration time $expiryPeriod = '1000';
// 数字货币币种(如果指定了method,则必传) $currency = 'USDT';
// 链网络(如果指定了method,则必传) $netWork = 'TRC20';
// 收银台版本(v1.0和v3.0属于有单模式版本;v2.0和v4.0属于无单模式) $orderVersion = 'v1.0';
$params = array( 'merchantCode' => $merchantCode, 'orderType' => $orderType, 'mchUserIid' => $mchUserIid, 'method' => $method, 'orderNum' => $orderNum, 'payMoney' => $payMoney, 'name' => $name, 'email' => $email, 'phone' => $phone, 'notifyUrl' => $notifyUrl, 'dateTime' => $dateTime, 'expiryPeriod' => $expiryPeriod, 'currency' => $currency, 'netWork' => $netWork, 'orderVersion' => $orderVersion );
ksort($params); $params_str = ''; foreach ($params as $key => $val) { $params_str = $params_str . $val; }
$sign = pivate_key_encrypt($params_str, $mchPrivateKey);
$params['sign'] = $sign;
$params_string = json_encode($params); $url = 'https://openapi.jayapayment.com/gateway/prepaidOrder'; $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($params_string)) );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//execute post $request = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 200) { $result = json_decode($request, true); echo "platRespCode :". $result['platRespCode'] . "\n"; echo "platRespMessage :". $result['platRespMessage'] . "\n"; echo "mchUserIid :". $result['mchUserIid'] . "\n"; echo "platOrderNum :". $result['platOrderNum'] . "\n"; echo "orderNum :". $result['orderNum'] . "\n"; echo "method :". $result['method'] . "\n"; echo "name :". $result['name'] . "\n"; echo "email :". $result['email'] . "\n"; echo "vaNumber :". $result['vaNumber'] . "\n"; echo "payMoney :". $result['payMoney'] . "\n"; echo "payFee :". $result['payFee'] . "\n"; echo "currency :". $result['currency'] . "\n"; echo "netWork :". $result['netWork'] . "\n"; echo "orderVersion :". $result['orderVersion'] . "\n"; echo "platSign :". $result['platSign'] . "\n";
$decryptStr = public_key_decrypt($result['platSign'], $platPublicKey); echo "decryptStr :". $decryptStr . "\n"; } else { echo $httpCode; }
function pivate_key_encrypt($data, $pivate_key) { $pivate_key = '-----BEGIN PRIVATE KEY-----'."\n".$pivate_key."\n".'-----END PRIVATE KEY-----'; $pi_key = openssl_pkey_get_private($pivate_key); $crypto = ''; foreach (str_split($data, 117) as $chunk) { openssl_private_encrypt($chunk, $encryptData, $pi_key); $crypto .= $encryptData; }
return base64_encode($crypto); }
function public_key_decrypt($data, $public_key) { $public_key = '-----BEGIN PUBLIC KEY-----'."\n".$public_key."\n".'-----END PUBLIC KEY-----'; $data = base64_decode($data); $pu_key = openssl_pkey_get_public($public_key); $crypto = ''; foreach (str_split($data, 128) as $chunk) { openssl_public_decrypt($chunk, $decryptData, $pu_key); $crypto .= $decryptData; }
return $crypto; }
}
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|