diff --git a/.gitignore b/.gitignore index a286a2b9..6f1c4033 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /kcfinder/cache/* */cache/* /author/document/* +*/settlement_files/* */statement_files/* */paypal_activities/* /author/document/* diff --git a/webht/third_party/pay/config/alipay.php b/webht/third_party/pay/config/alipay.php index 1c846214..1906ab44 100644 --- a/webht/third_party/pay/config/alipay.php +++ b/webht/third_party/pay/config/alipay.php @@ -1,13 +1,4 @@ load->library('alipay/AopSdk'); // real URL - $this->config->load('alipay'); + $this->config->load('alipay', true); $this->config->load('wxpay', true); // test URL // $this->config->load('dev_alipay'); @@ -54,38 +55,49 @@ class AlipayTradeService extends CI_Controller $this->load->helper('payment'); $this->load->model('Online_payment_account_model', 'payment_model'); - $this->gateway_url = $this->config->item('gatewayUrl'); - $this->appid = $this->config->item('app_id'); - $this->seller_id = $this->config->item('seller_id'); - $this->private_key = $this->config->item('merchant_private_key'); - $this->alipay_public_key = $this->config->item('alipay_public_key'); - $this->charset = $this->config->item('charset'); - $this->signtype = $this->config->item('sign_type'); - $this->timeout_express = $this->config->item('timeout_express'); + $this->set_merchant('cht'); - $this->return_url = $this->config->item('return_url'); - $this->notify_url = $this->config->item('notify_url'); + header('Access-Control-Allow-Origin:*'); + header('Access-Control-Allow-Methods:POST, GET'); + header('Access-Control-Max-Age:0'); + header('Access-Control-Allow-Headers:x-requested-with, Content-Type'); + } - if(empty($this->appid)||trim($this->appid)==""){ - log_message('error','Alipay ERROR appid should not be NULL!'); + private function set_merchant($account = 'cht') + { + $this->merchant_account = $account; + + $this->ali_site_config = $this->config->item(strtolower($account), 'alipay'); + + $this->gateway_url = $this->ali_site_config['gatewayUrl']; + $this->appid = $this->ali_site_config['app_id']; + $this->seller_id = $this->ali_site_config['seller_id']; + $this->private_key = $this->ali_site_config['merchant_private_key']; + $this->alipay_public_key = $this->ali_site_config['alipay_public_key']; + $this->charset = $this->ali_site_config['charset']; + $this->signtype = $this->ali_site_config['sign_type']; + $this->timeout_express = $this->ali_site_config['timeout_express']; + + $this->return_url = $this->ali_site_config['return_url']; + $this->notify_url = $this->ali_site_config['notify_url']; + + if (empty($this->appid) || trim($this->appid) == "") { + log_message('error', 'Alipay ERROR appid should not be NULL!'); } - if(empty($this->private_key)||trim($this->private_key)==""){ - log_message('error','Alipay ERROR private_key should not be NULL!'); + if (empty($this->private_key) || trim($this->private_key) == "") { + log_message('error', 'Alipay ERROR private_key should not be NULL!'); } - if(empty($this->alipay_public_key)||trim($this->alipay_public_key)==""){ - log_message('error','Alipay ERROR alipay_public_key should not be NULL!'); + if (empty($this->alipay_public_key) || trim($this->alipay_public_key) == "") { + log_message('error', 'Alipay ERROR alipay_public_key should not be NULL!'); } - if(empty($this->charset)||trim($this->charset)==""){ - log_message('error','Alipay ERROR charset should not be NULL!'); + if (empty($this->charset) || trim($this->charset) == "") { + log_message('error', 'Alipay ERROR charset should not be NULL!'); } - if(empty($this->gateway_url)||trim($this->gateway_url)==""){ - log_message('error','Alipay ERROR gateway_url should not be NULL!'); + if (empty($this->gateway_url) || trim($this->gateway_url) == "") { + log_message('error', 'Alipay ERROR gateway_url should not be NULL!'); } - header('Access-Control-Allow-Origin:*'); - header('Access-Control-Allow-Methods:POST, GET'); - header('Access-Control-Max-Age:0'); - header('Access-Control-Allow-Headers:x-requested-with, Content-Type'); } + public function index() { $this->note_list(); @@ -752,6 +764,7 @@ class AlipayTradeService extends CI_Controller $response = $this->aopclientRequestExecute ($request); $response = $response->alipay_trade_query_response; + // log_message('error','test:rrr2 ' . __CLASS__ . PHP_EOL . var_export($response, 1)); return $response; } @@ -794,6 +807,17 @@ class AlipayTradeService extends CI_Controller return $this->output->set_content_type('application/json')->set_output(json_encode($response)); } + public function get_billfile($date=NULL) + { + ignore_user_abort(true); + $all_account = array_keys($this->config->item('alipay')); + foreach ($all_account as $key => $account) { + $this->set_merchant($account); + $this->download_billfile($date); + sleep(2); + } + return false; + } /*! * 对账单 * 流程: @@ -805,7 +829,7 @@ class AlipayTradeService extends CI_Controller * @date 2017-10-10 * @param [type] $date 按天yyyy-MM-dd;按月yyyy-MM */ - public function get_billfile($date=NULL) + public function download_billfile($date=NULL) { ignore_user_abort(true); $request = new AlipayDataDataserviceBillDownloadurlQueryRequest(); @@ -822,8 +846,8 @@ class AlipayTradeService extends CI_Controller } set_time_limit(0); $file = file_get_contents($response->$responseNode->bill_download_url); - $file_name = FCPATH.'download_statement\settlement_files\alipay\\' . $date . ".zip"; - $target = FCPATH.'download_statement\settlement_files\alipay\\' . $date ; + $file_name = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date . ".zip"; + $target = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date ; file_put_contents($file_name, $file); $biz_detail_table = array(); $biz_data_title = $this->bill_data_title(); @@ -855,6 +879,7 @@ class AlipayTradeService extends CI_Controller } $row_arr[$title] = trim($row[$key]); } + $row_arr['app_id'] = $this->appid; $biz_detail_table[] = $row_arr; } @@ -869,7 +894,7 @@ class AlipayTradeService extends CI_Controller foreach ($biz_detail_table as $key => $row) { $total_amount = 0;$trade_type='';$trade_no = '';$has_charge=null; if (isset($row['finance_id'])) { - if ($row['biz_type'] !== '其它') { + if ($row['biz_type'] !== '其它' && $row['biz_type'] !== '在线支付') { continue; } $total_amount = floatval($row['income'])>0 ? $row['income'] : $row['expenditure']; @@ -1000,6 +1025,7 @@ class AlipayTradeService extends CI_Controller * $size:生成二维码的尺寸,宽度和高度的值 * $lev:可选参数,纠错等级 * $margin:生成的二维码离边框的距离 + * @example http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=L|0&chl=content */ function create_erweima($content, $size = '200', $lev = 'L', $margin= '0') { $content = urlencode($content); @@ -1019,8 +1045,14 @@ class AlipayTradeService extends CI_Controller if (!empty($data['keywords'])) { $data['notelist'] = $this->Alipay_note_model->search_key($data['keywords']); /** 手动查询通过收钱码的收款, 必须输入交易号 */ + // if (true) { // debug: 0 if (empty($data['notelist'])) { $query_pay = $this->query_pay($data["keywords"]); + if (empty($query_pay)) { + $this->set_merchant('trippest'); + $query_pay = $this->query_pay($data["keywords"]); + } + $query_pay->app_id = $this->appid; if ( ! empty($query_pay) && strval($query_pay->code)==="10000" && in_array(strval($query_pay->trade_status), array("TRADE_SUCCESS", "TRADE_FINISHED")) ) { $pay_type = $query_pay->total_amount>0 ? "pay" : "refund";