Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: Binance_pay.php
<?php class Binance_pay { private $api_key; private $secret_key; private $timestamp; private $nonce; private $return_url; private $cancel_url; public function __construct() { $this->timestamp = $this->timestamp(); $this->nonce = $this->nonce(); $this->return_url = $this->return_url(); $this->cancel_url = $this->cancel_url(); } public function create_order($merchant_trade_no, $amount, $currency, $api_key, $secret_key, $goodsDetails) { // Request body if(stripos($merchant_trade_no, "R") !== false){ $url = array( 'returnUrl' => $goodsDetails['url']['returnUrl'], 'cancelUrl' => $goodsDetails['url']['cancelUrl'], ); }else{ $url = array( 'returnUrl' => $this->return_url, 'cancelUrl' => $this->cancel_url, ); } unset($goodsDetails['url']); $request = [ 'env' => [ 'terminalType' => 'WEB', ], 'merchantTradeNo' => $merchant_trade_no, 'orderAmount' => $amount, 'currency' => $currency, 'returnUrl' => $url['returnUrl'], 'cancelUrl' => $url['cancelUrl'], 'goods' => $goodsDetails /*[ 'goodsType' => '01', 'goodsCategory' => 'D000', 'referenceGoodsId' => '7876763A3B', 'goodsName' => 'Ice Cream', 'goodsDetail' => 'Greentea ice cream cone', ]*/ ]; $json_request = json_encode($request); $payload = $this->timestamp."\n".$this->nonce."\n".$json_request."\n"; $signature = strtoupper(hash_hmac('SHA512', $payload, $secret_key)); //$signature = strtoupper(hash_hmac('SHA512', $payload, $this->secret_key)); $headers[] = "Content-Type: application/json"; $headers[] = "BinancePay-Timestamp: " . $this->timestamp; $headers[] = "BinancePay-Nonce: " . $this->nonce; $headers[] = "BinancePay-Certificate-SN: " . $api_key; //$headers[] = "BinancePay-Certificate-SN: " . $this->api_key; $headers[] = "BinancePay-Signature: $signature"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, "https://bpay.binanceapi.com/binancepay/openapi/v2/order"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_request); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch); $result = json_decode($result, true); return $result; } public function query_order($merchant_trade_no, $api_key, $secret_key) { // Request body $request = [ 'merchantTradeNo' => base64_decode($merchant_trade_no) ]; $json_request = json_encode($request); $payload = $this->timestamp."\n".$this->nonce."\n".$json_request."\n"; $signature = strtoupper(hash_hmac('SHA512', $payload, $secret_key)); $headers[] = "Content-Type: application/json"; $headers[] = "BinancePay-Timestamp: " . $this->timestamp; $headers[] = "BinancePay-Nonce: " . $this->nonce; $headers[] = "BinancePay-Certificate-SN: " . $api_key; $headers[] = "BinancePay-Signature: $signature"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, "https://bpay.binanceapi.com/binancepay/openapi/v2/order/query"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_request); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch); $result = json_decode($result, true); return $result; } private function timestamp() { return round(microtime(true) * 1000); } private function nonce() { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $nonce_str = ''; for($i=1; $i <= 32; $i++) { $pos = mt_rand(0, strlen($chars) - 1); $char = $chars[$pos]; $nonce_str .= $char; } return $nonce_str; } private function dump($data) { echo '<pre>';print_r($data);die; } private function debug() { echo time();die; } public function return_url() { return base_url('page/order_placed?event=return'); //'https://codeunlocksource.com/binance-pay-api/callback.php?event=return'; } public function cancel_url() { return base_url('page/order_cancelled?event=cancel'); //'https://codeunlocksource.com/binance-pay-api/callback.php?event=cancel'; } }