File: /var/www/html/wp-content/plugins/ganryu_shop/libs/GanryuEpsCredit.php.bak20160930
<?php
class GanryuEpsCredit{
var $config;
function __construct($config){
$this->config = $config;
}
function buildQuery($data){
$encode = $this->config['send_encode'];
$body = "";
foreach ($data as $nm=>$v){
$v = mb_convert_encoding($v, $encode);
if ($body) $body .= "&";
$body .= urlencode($nm);
$body .= "=";
$body .= urlencode($v);
}
return $body;
}
function connectEps($sendurl, $senddata){
$body = $this->buildQuery($senddata);
$curl = curl_init($sendurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$res = curl_exec($curl);
$st = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($st != 200){
return false;
}
$res = preg_replace_callback('/^(<\?xml.*)encoding="[\w-]+"(.*\?>)/', function($m){return $m[1].$m[2];}, $res);
$xml = simplexml_load_string($res);
if (!$xml){
return false;
}
$recencode = $this->config['receive_encode'];
$inencode = $this->config['inner_encode'];
$ret = array();
foreach ($xml->result as $subitm){
foreach ($subitm->attributes() as $key=>$val){
$ret[$key] = mb_convert_encoding(urldecode((string)$val), $inencode, $recencode);
}
}
return $ret;
}
function connectPurchase($data){
$senddata = array(
'contract_code'=>$this->config['contract_code'],
'user_id'=>$data['credit_userid'],
'order_number'=>$data['order_number'],
'st_code'=>'11011-0000-00000-00000-00000-00000-00000',
'mission_code'=>1,
'item_price'=>$data['price'],
'item_name'=>$data['item_name'],
'item_code'=>$data['item_code'],
'user_mail_add'=>$data['user_mail_add'],
'user_name'=>$data['user_name'],
'process_code'=>$data['process_code'],
'xml'=>1
);
if (isset($data['delivery_code'])){
$labs = array(
'delivery_code',
'consignee_postal',
'consignee_name',
'consignee_address',
'consignee_tel',
'orderer_postal',
'orderer_name',
'orderer_address',
'orderer_tel',
);
foreach ($labs as $lb){
$senddata[$lb] = $data[$lb];
}
}
$sendurl = $this->config['url']['create_purchase'];
return $this->connectEps($sendurl, $senddata);
}
function connectFanclubPurchase($data){
if(date("Ymd")<=20160930) $mission_code = 24;
else $mission_code = 22;
$senddata = array(
'contract_code'=>$this->config['contract_code'],
'user_id'=>$data['credit_userid'],
'order_number'=>$data['order_number'],
'st_code'=>'10000-0000-00000-00000-00000-00000-00000',
'mission_code'=>$mission_code,
'item_price'=>$data['price'],
'item_name'=>$data['item_name'],
'item_code'=>$data['item_code'],
'user_mail_add'=>$data['user_mail_add'],
'user_name'=>$data['user_name'],
'process_code'=>$data['process_code'],
'xml'=>1
);
$sendurl = $this->config['url']['create_purchase'];
return $this->connectEps($sendurl, $senddata);
}
function connectFanclubCancel($data){
$senddata = array(
'contract_code'=>$this->config['contract_code'],
'user_id'=>$data['credit_userid'],
'item_code'=>$data['item_code'],
);
$sendurl = $this->config['url']['create_regularly_cancel'];
return $this->connectEps($sendurl, $senddata);
}
function connectGetSales($code){
$senddata = array(
'contract_code'=>$this->config['contract_code'],
'order_number'=>$code,
'xml'=>1
);
$sendurl = $this->config['url']['get_sales'];
return $this->connectEps($sendurl, $senddata);
}
}