config->load('iPayLinks'); // $this->config->load('dev_iPayLinks'); // test $this->load->model('IPayLinks_model'); $this->load->model('Note_model'); $this->gatewayUrl = $this->config->item('gatewayUrl'); $this->queryUrl = $this->config->item('queryUrl'); $this->return_url = $this->config->item('returnUrl'); $this->notify_url = $this->config->item('noticeUrl'); $this->pay_info_arr['version'] = $this->query_info_arr['version'] = $this->config->item('version'); $this->pay_info_arr['partnerId'] = $this->query_info_arr['partnerId'] = "10000004000"; // $this->pay_info_arr['partnerId'] = $this->query_info_arr['partnerId'] = $this->config->item('partnerId'); $this->pay_info_arr['charset'] = $this->query_info_arr['charset'] = $this->config->item('charset'); $this->pay_info_arr['signType'] = $this->query_info_arr['signType'] = $this->config->item('signType'); $this->pay_info_arr['siteId'] = $this->config->item('siteId'); $this->pay_info_arr['tradeType'] = $this->config->item('tradeType'); $this->pay_info_arr['borrowingMarked'] = $this->config->item('borrowingMarked'); $this->pay_info_arr['noticeUrl'] = $this->config->item('noticeUrl'); $this->pay_info_arr['mcc'] = $this->config->item('mcc'); $this->pay_info_arr['payType'] = $this->config->item('payType'); $this->pay_info_arr['payMode'] = $this->config->item('payMode'); $this->pay_info_arr['currencyCode'] = $this->config->item('currencyCode'); $this->query_info_arr['mode'] = $this->config->item('query_mode'); $this->query_info_arr['type'] = $this->config->item('query_type'); if(empty($this->pay_info_arr['partnerId'])||trim($this->pay_info_arr['partnerId'])==""){ throw new Exception("partnerId should not be NULL!"); } if(empty($this->pay_info_arr['siteId'])||trim($this->pay_info_arr['siteId'])==""){ throw new Exception("siteId should not be NULL!"); } } public function index() { $this->note_list(); } public function note_list() { $data = array(); $data["paytext"] = $this->payment_status(); $data["keywords"] = $this->input->get_post("keywords"); $data["date"] = $this->input->get_post("date"); empty($data['date']) ? $data['date'] = date('Y-m-d') : false; if (!empty($data['keywords'])) { $data['notelist'] = $this->Note_model->search_key($data['keywords']); } else { $data['notelist'] = $this->Note_model->search_date($data['date']); } $this->load->view("iPayLinks_list",$data); return; } //失败记录列表 public function note_faillist() { $data = array(); $data["paytext"] = $this->payment_status(); //有关键词则不限制日期 $data['search_key'] = $this->input->post('keywords'); $data['date'] = $this->input->get_post('date'); empty($data['date']) ? $data['date'] = date('Y-m-d') : false; $data['notelist'] = $this->Note_model->failnote(100); $this->load->view("iPayLinks_list",$data); } public function get_url_string() { $param = ($this->input->get_post('param')); return base64_decode($param); } /*! * 跳转到信用卡信息页面,包含订单信息 * @author LYT * @date 2017-08-11 */ public function order_info() { $param = $this->input->get_post("param"); $data['form_html'] = ""; $data['year_html'] = ""; $this_year = date('Y'); for ($i=0; $i < 10; $i++) { $data['year_html'] .= ""; } $data['month_html'] = ""; for ($i=1; $i < 13; $i++) { $data['month_html'] .= ""; } $this->get_order_info(); $data['description'] = $param_arr = str_replace("\n", "
", $this->order_info_arr['goodsDesc']) ; bcscale(2); $data['amount'] = strval(bcdiv($this->order_info_arr['orderAmount'], 100)); $data['currencyCode'] = $this->pay_info_arr['currencyCode']; $data['orderId'] = $this->order_info_arr['orderId']; $this->load->view("iPayLinks_index",$data); } /*! * 跳转到付款结束页面 * @author LYT * @date 2017-08-17 * @param array $data 付款结果信息 */ public function order_done($data=NULL) { if (empty($data)) { $data["code"] = 1; $data["msg"] = "Unknow request"; $data["error_code"] = "Unknow"; } $url_query = ""; foreach ($data as $key => $v) { $url_query .= $key . "=" . urlencode($v) ."&"; } redirect($this->return_url . "?" . substr($url_query, 0, -1)); } public function load_return() { $data["code"] = $this->input->get_post("code"); $data["msg"] = $this->input->get_post("msg"); $data["error_code"] = $this->input->get_post("error_code"); $this->load->view("iPayLinks_rep",$data); } /*! * 接收订单信息 * @author LYT * @date 2017-08-11 */ public function get_order_info() { $param_string = $this->get_url_string(); @parse_str($param_string, $param_arr); if ( ! $param_string || empty($param_arr['order_id'])) { $this->order_done(); return false; } $this->order_info_arr['orderId'] = $this->order_info_arr['deviceFingerprintId'] = trim($param_arr['order_id']); $this->order_info_arr['goodsName'] = trim($param_arr['goods_name']); $this->order_info_arr['goodsDesc'] = trim($param_arr['goods_desc']); // 两位小数去掉小数点; // 1.00 USD => 100 bcscale(0); $this->order_info_arr['orderAmount'] = intval(bcmul(floatval(trim($param_arr['order_amount'])), 100)); $this->order_info_arr['customerIP'] = $this->input->ip_address(); $this->order_info_arr['submitTime'] = date('YmdHis'); $this->pay_info_arr['currencyCode'] = !empty($param_arr['currency']) ? trim($param_arr['currency']) : $this->config->item('currencyCode'); $this->return_url = !empty($param_arr['return_url']) ? trim($param_arr['return_url']) : $this->return_url; $this->notify_url = !empty($param_arr['notify_url']) ? trim($param_arr['notify_url']) : $this->notify_url; if ($this->notify_url) { $this->pay_info_arr['noticeUrl'] = $this->notify_url ; } } public function get_card_info() { $this->card_info_arr['cardHolderNumber'] = trim(str_replace(" ", "", $this->input->get_post('cardHolderNumber'))); $this->card_info_arr['cardHolderFirstName'] = trim($this->input->get_post('cardHolderFirstName')); $this->card_info_arr['cardHolderLastName'] = trim($this->input->get_post('cardHolderLastName')); $this->card_info_arr['cardExpirationMonth'] = trim($this->input->get_post('cardExpirationMonth')); $this->card_info_arr['cardExpirationMonth'] = $this->card_info_arr['cardExpirationMonth'] > 9 ? $this->card_info_arr['cardExpirationMonth'] : "0".$this->card_info_arr['cardExpirationMonth']; $this->card_info_arr['cardExpirationYear'] = substr(trim($this->input->get_post('cardExpirationYear')),2,2); $this->card_info_arr['securityCode'] = trim(str_replace(" ","",$this->input->get_post('securityCode'))); $this->card_info_arr['cardHolderEmail'] = trim($this->input->get_post('cardHolderEmail')); // 记录付款人联系信息 $card_holder_arr = array( "n" => substr($this->card_info_arr['cardHolderFirstName']." ".$this->card_info_arr['cardHolderLastName'],0,50), "e" => substr($this->card_info_arr['cardHolderEmail'],0,50) ); $this->card_info_arr['remark'] = json_encode($card_holder_arr); } public function order_pay() { $this->get_order_info(); $this->get_card_info(); $form_request = array_merge($this->pay_info_arr,$this->card_info_arr,$this->order_info_arr); $form_request['signMsg'] = $this->generate_sign($form_request); $resp = $this->curl($this->gatewayUrl,$form_request); $respWellFormed = $this->verify_sign($resp); // 未得到结果 if (false === $respWellFormed->data) { $this->order_done(); return; } // test // $this->ipaylinks_notice($resp); // 返回结果 $ret = $this->result_2_return_url($respWellFormed->data->resultCode,$respWellFormed->data->resultMsg); $this->order_done($ret); return; } /*! * 主动查询完成的交易 * 得到结果后进行入库处理,包括失败的交易 * @author LYT * @date 2017-08-29 * @param Object $respObject 交易完成得到的xml Object */ public function query_pay_result($respObject) { $this->query_info_arr["queryOrderId"] = $this->create_guid(); $this->query_info_arr["orderId"] = $respObject->orderId; $this->query_info_arr["beginTime"] = $respObject->acquiringTime; $this->query_info_arr["endTime"] = $respObject->completeTime; $this->query_info_arr["signMsg"] = $this->generate_sign($this->query_info_arr); $resp = $this->curl($this->queryUrl,$this->query_info_arr); $query_resp = $this->verify_sign($resp); // 未得到结果 if (false === $query_resp->data) { $this->order_done(); return; } // 查询到交易结果的写入记录 $this->iPayLinks_log($query_resp); // test // log_message('error',"\n---------------------------------end--------------------------------\n\n\n"); return; } public function query_pay($orderid,$day_offset = 3) { $this->query_info_arr["queryOrderId"] = $this->create_guid(); $this->query_info_arr["orderId"] = $orderid; $this->query_info_arr["beginTime"] = date('YmdHis',strtotime("-$day_offset days")); $this->query_info_arr["endTime"] = date('YmdHis',strtotime("+$day_offset days")); $this->query_info_arr["mode"] = 2; $this->query_info_arr["signMsg"] = $this->generate_sign($this->query_info_arr); $resp = $this->curl($this->queryUrl,$this->query_info_arr); echo $resp; return; } /*! * 订单业务处理 * * 查询写入交易记录 iPayLinks_log * * 异步通知更新 iPayLinks_log * * 邮件通知外联 定时处理 * * 更新订单收款状态 */ /*! * 根据查询得到的结果入库 * 支付订单,单笔查询 * @author LYT * @date 2017-08-29 * @param ArrayObject $query_resp->check 验签结果 [boolean] * $query_resp->data 查询得到的交易结果 [SimpleXMLElement Object] */ public function iPayLinks_log($query_resp) { bcscale(2); $detail = $query_resp->data->details->detail; if (true === $this->if_note_exists($detail->dealId)) { // 已存在记录,更新stateCode,payAmount,payer,payerEmail $this->Note_model->update_query( strval($detail->dealId), strval($detail->stateCode), strval(bcdiv(floatval($detail->payAmount), 100) ) ); return false; } } public function if_note_exists($dealId) { return $this->Note_model->note_exists($dealId) ? true : false; } /*! * 邮件外联 * @author LYT * @date 2017-08-29 * @param string $orderid 订单号 */ public function batch_send_note($pn_txn_id = false) { $data = array(); $int = 0; //优先处理指定的交易号,用于修正交易号直接发送通知 if ( ! empty($pn_txn_id)) { $data['unsend_list'] = array($this->Note_model->note($pn_txn_id)); } // 待处理的 if (empty($data['unsend_list'])) { $data['unsend_list'] = $this->Note_model->unsend(10); } //没有未处理的数据再查找处理失败的数据 if (empty($data['unsend_list'])) { $data['unsend_list'] = $this->Note_model->failnote(20); } $show_index = 0; foreach ($data['unsend_list'] as $item) { //已经发送的不处理,防止重复发送 if ($item->IPL_sent == 'send') { continue; } //退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理 if ($item->IPL_payType == 'Refunded') { $this->Note_model->update_send($item->IPL_dealId, 'send'); continue; } //只处理完成状态,其他状态由陆燕处理 if (strcmp(trim($item->IPL_resultCode), "0000")) { $this->Note_model->update_send($item->IPL_dealId, 'sendfail'); continue; } //检测是否是APP订单,默认不处理 // if ((strpos($item->pn_memo, 'China Train Booking') !== false) || (strpos($item->pn_memo, 'ChinaTrainBooking') !== false)) { //APP自动出票的订单不需要处理 // $this->Note_model->update_send($item->IPL_dealId, 'send'); // continue; // } //根据note信息找到订单号 $orderid_info = $this->analysis_orderid($item->IPL_orderId); //找不到订单号,设置为发送失败标示 if (empty($orderid_info)) { $this->Note_model->update_send($item->IPL_dealId, 'sendfail'); continue; } //根据订单号查找外联信息 $orderid_info = json_decode($orderid_info); $advisor_info = $this->IPayLinks_model->get_order($orderid_info->orderid, false, $orderid_info->ordertype); //查不到订单信息 if (empty($advisor_info)) { $this->Note_model->update_send($item->IPL_dealId, 'sendfail'); continue; } //更新正确的订单信息到记录中,以这个为主 $this->Note_model->set_invoice($item->IPL_dealId, $orderid_info->orderid . '_' . $orderid_info->ordertype); //检测是否是APP订单,默认不处理 if ($orderid_info->ordertype == 'A') { //APP自动出票的订单不需要处理 $this->Note_model->update_send($item->IPL_dealId, 'send'); continue; } //添加支付信息入库 //没有分配订单之前先添加付款记录,这个过程可能会执行多次,必须在添加记录前查找是否有数据 if (!empty($orderid_info)) { //更新还没有填的客邮和交易号de收款记录(商务订单) if (isset($advisor_info->order_type) && $advisor_info->order_type == 0) { $ht_memo = '交易号(自动录入):' . $item->IPL_dealId; $GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0; //CHTAPP订单添加记录前判断是否有记录,以前的APP版本没有交易号,只能拿金额来判断 if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP') { //只判断前6位字符,CHTAPP-fr CHTAPP-jp等各语种都属于APP订单 // $this->IPayLinks_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, '', $item->pn_payer_email, $item->IPL_dealId, $ht_memo); // if ($advisor_info->COLI_WebCode == 'CHTAPP' && $advisor_info->COLI_State == 11) { //只修改APP组的订单状态,并且订单进度是我的订单 // $this->IPayLinks_model->update_biz_coli_state($GAI_COLI_SN, 8); //把订单状态改为已付款 // } } else { $this->IPayLinks_model->add_account_info( $GAI_COLI_SN, $advisor_info->COLI_ID, $item->IPL_orderAmount, $item->IPL_completeTime, mb_strtoupper($item->IPL_currencyCode), $item->IPL_completeTime, $item->IPL_completeTime, $item->IPL_acquiringTime, $item->IPL_payerName, $item->IPL_payerEmail, $item->IPL_dealId, $ht_memo ); } } //更新还没有填的客邮和交易号de收款记录(传统订单) elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) { $ht_memo = '交易号(自动录入):' . $item->IPL_dealId; $GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0; $this->IPayLinks_model->add_tour_account_info( $GAI_COLI_SN, $item->IPL_orderAmount, $item->IPL_acquiringTime, mb_strtoupper($item->IPL_currencyCode), $item->IPL_completeTime, $item->IPL_completeTime, $item->IPL_acquiringTime, $item->IPL_payerName, $item->IPL_payerEmail, $item->IPL_dealId, $ht_memo ); //添加汉特的订单提醒 $this->IPayLinks_model->update_coli_introduction($GAI_COLI_SN, '已支付 ' . mb_strtoupper($item->IPL_currencyCode) . $item->IPL_orderAmount); } } $opi_email = !empty($advisor_info->OPI_Email) ? $advisor_info->OPI_Email : ''; //lussie@chinahighlights.net $opi_firstname = !empty($advisor_info->OPI_FirstName) ? $advisor_info->OPI_FirstName : !empty($advisor_info->OPI_Name) ? $advisor_info->OPI_Name : ''; //lussie //没有外联信息表示订单未分配 if (empty($opi_email) || empty($opi_firstname)) { $this->Note_model->update_send($item->IPL_dealId, 'sendfail'); continue; } //添加邮件发送记录 //给外联发送通知邮件 $fromName = 'iPayLinks'; $fromEmail = ''; $toName = !empty($opi_firstname) ? $opi_firstname : ''; $toEmail = !empty($opi_email) ? $opi_email : ''; $subject = $orderid_info->orderid . '_' . $orderid_info->ordertype . ' / ' . $item->IPL_orderAmount . $item->IPL_currencyCode . ' / ' . $fromName; $body = $this->load->view('receipt_mail', $item, true); $M_RelatedInfo = $item->IPL_sn; $M_AddTime = $item->IPL_completeTime; $M_State = 0; $this->IPayLinks_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'iPayLinks note'); //添加邮件发送记录 end $this->Note_model->update_send($item->IPL_dealId, 'send'); $int++; } // 批量结果 if (empty($pn_txn_id)) { echo "done. recorde count:".$int; } return; } //解析出订单号 public function analysis_orderid($note_invoice_string) { $data = array(); //空字符串或者小于8位都属于不正确的订单号 if (empty($note_invoice_string) || strlen($note_invoice_string) < 8) { return false; } //APP订单处理,如标题China Train Booking-160617462 if ((strpos($note_invoice_string, 'China Train Booking') !== false) || (strpos($note_invoice_string, 'ChinaTrainBooking') !== false)) { $note_invoice_string = explode('-', $note_invoice_string); if (isset($note_invoice_string[1])) { $note_invoice_string = trim($note_invoice_string[1]); } return json_encode(array('orderid' => $note_invoice_string, 'ordertype' => 'A')); //APP订单,不需要处理交易记录和通知 } //订单号例子 160420021_B--9608 //Tracking code:2016-05-06-JJ160319027 /Travel advisor:Fiona Jiang /Content:Shanghai, Beijing, Pingyao, Xian, Guilin, Yangshuo, S if (strpos($note_invoice_string, 'Tracking Code:') !== false) { $note_invoice_string = explode('Tracking Code:', $note_invoice_string); $note_invoice_string = explode('Travel Advisor', $note_invoice_string[1]); $note_invoice_string = trim($note_invoice_string[0]); } //订单号过滤 $note_invoice_string = explode('--', $note_invoice_string); $note_invoice_string = $note_invoice_string[0]; $note_invoice_string = explode('_', $note_invoice_string); //订单类型识别 $ordertype = 'N'; if (isset($note_invoice_string[1])) { $ordertype_temp = trim($note_invoice_string[1]); if (substr($ordertype_temp, 0, 1) == 'T') { $ordertype = 'T'; } elseif (substr($ordertype_temp, 0, 1) == 'B') { $ordertype = 'B'; } } //手机订单、机票订单都没有加标示,在这里帮加上,暂时的,今后还是要在网前设置好 if ($ordertype == 'N' && isset($note_invoice_string[0])) { $orderid_temp = $note_invoice_string[0]; if (strlen($orderid_temp) == 9 && substr($orderid_temp, 0, 2) == '16') { $ordertype = 'B'; } } //前台预付款订单,以45开头,如45117640类型的订单号,这个类型的订单会分配到某个新订单去,需要查找COLI_AddCode来找新订单号,然后再发送通知 if ($ordertype == 'N' && isset($note_invoice_string[0])) { $orderid_temp = $note_invoice_string[0]; if (strlen($orderid_temp) == 8 && substr($orderid_temp, 0, 2) == '45') { $ordertype = 'M'; } } //新的订单号14733661876255 if ($ordertype == 'N' && isset($note_invoice_string[0])) { $orderid_temp = $note_invoice_string[0]; if (strlen($orderid_temp) == 14 && substr($orderid_temp, 0, 2) == '14') { $ordertype = 'M'; } } if ($ordertype == 'N') { return false; //没有编号的订单直接显示错误,由人工分配 } $note_invoice_string = $note_invoice_string[0]; $note_invoice_string = explode(',', $note_invoice_string); $orderid = trim($note_invoice_string[0]); $temp_orderid = explode('-', $orderid); if (isset($temp_orderid[1])) { $orderid = trim($temp_orderid[1]); } $tempid = explode(' ', $orderid); $pm_orderid = $tempid[0]; //订单号 if (empty($pm_orderid) || strlen($pm_orderid) < 8) { return false; } return json_encode(array('orderid' => $pm_orderid, 'ordertype' => $ordertype)); } /*! * 接收异步通知 * 返回200 * @author LYT * @date 2017-08-30 * @param string $resp 原始xml */ public function ipaylinks_notice($resp=NULL) { if ($resp !== NULL) { $resp_arr = $resp; } else { $resp_arr = $this->input->post(); } $asyns_resp = $this->verify_sign($resp_arr); // 未得到结果 if (empty($asyns_resp->data->orderId)) { echo "200"; return; } // dealId $dealId = trim($asyns_resp->data->dealId) ; $tmp_deal = $dealId ? $dealId : $this->create_guid(); // payer info $payer_info = json_decode($asyns_resp->data->remark); $payer_name = $payer_info->n; $payer_email = $payer_info->e; bcscale(2); // 支付成功 // 查询支付结果;入库处理 if ( ! empty($dealId)) { $this->Note_model->save_ipl( strval($tmp_deal) ,strval($asyns_resp->data->orderId) ,strval($asyns_resp->data->currencyCode) ,strval(bcdiv(floatval($asyns_resp->data->orderAmount), 100)) ,NULL ,NULL ,strval(date('Y-m-d H:i:s',strtotime($asyns_resp->data->acquiringTime))) ,strval(date('Y-m-d H:i:s',strtotime($asyns_resp->data->completeTime))) ,json_encode($asyns_resp->data) ,strval("pay") ,strval($asyns_resp->data->resultCode) ,strval($asyns_resp->data->resultMsg) ,strval($payer_name) ,strval($payer_email) ); $query = $this->query_pay_result($asyns_resp->data); } // 返回状态码200 echo "200"; return; } /*! * 生成签名串 * @author LYT * @date 2017-08-17 * @param array $request 待签名的请求数据/返回结果 * @return string 签名字符串 */ protected function generate_sign($request) { ksort($request); unset($request['signMsg']); $request['pkey'] = "30819f300d06092a864886f70d010101050003818d00308189028181008c903972be5509375edec0d6793d8d3eb533334d146069b5dfcdafd24e5c7d0a05d1774488ea257d504a18c9098d798c0f523f3ad722e3e9c32ae7fecd7e734b340b9c8ff805aa32d0a49cb6df9eca3bb6954d966f6148533a8d667aabb55b2762dcd06308c94d24d257dfdb2ad86b46702774c51e7627e5b707d52224ef794b0203010001"; // $request['pkey'] = $this->config->item('pkey'); $param_str = ""; foreach ($request as $sysParamKey => $sysParamValue) { if ($sysParamKey == "details") { $param_str .= trim($sysParamKey)."=["; $value_cnt = count($sysParamValue); $value_int = 0; foreach ($sysParamValue as $vk => $detail) { $value_int++; $param_str .= "{"; $v_cnt = count($detail); $v_int = 0; foreach ($detail as $dk => $dv) { $v_int ++; if (false === $this->checkEmpty($dv)) { $param_str .= trim($dk)."=" . trim($this->characet($dv,"UTF-8")); if ($v_int != $v_cnt) { $param_str .= ","; } } } $param_str .= "}"; if ($value_int != $value_cnt) { $param_str .= ","; } } $param_str .= "]&"; continue; } if (false === $this->checkEmpty($sysParamValue)) { $param_str .= trim($sysParamKey)."=" . trim($this->characet($sysParamValue,"UTF-8")) . "&"; } } $param_str = substr($param_str, 0, -1); $param_str = md5($param_str); $request['signMsg'] = $param_str; unset($request['pkey']); return $param_str; } /*! * 验证签名 * @author LYT * @date 2017-08-17 * @param mix $resp API返回的原始xml或异步返回的post数组 */ protected function verify_sign($resp=NULL) { $ret = new ArrayObject(); $ret->check = false; $ret->data = NULL; if (is_array($resp)) { // 异步通知接收到的是post数组 $ret->data = $respObject = (Object) $resp; $ref = ""; } else { $ref = $_SERVER['HTTP_REFERER']; $r = iconv("UTF-8", "UTF-8//IGNORE", $resp); $ret->data = $respObject = @ simplexml_load_string($resp); // test // log_message("error", "xml result: \n $resp"); if (false === $respObject) { log_message('error','iPayLinks return ERROR ! Unknow ERROR ! Original return:'.$resp."; From: ".$ref); return $ret; } } $rep_sign = $this->generate_sign((array)$respObject); if (strcmp($rep_sign,$respObject->signMsg)) { log_message('error','iPayLinks sign ERROR ! orderId:'.$respObject->orderId.'; dealId:'.$respObject->dealId . "; Original return:".$resp."; From: ".$ref); return $ret; } // partnerId if (strcmp($respObject->partnerId, $this->pay_info_arr['partnerId'])) { log_message("error", " iPayLinks ERROR partnerId verify failed ".$respObject->partnerId." !== ".$this->pay_info_arr['partnerId'].'; orderId:'.$respObject->orderId.'; dealId:'.$respObject->dealId."; From: ".$ref); return $ret; } // resultCode payment failed if (strcmp(strval($respObject->resultCode), "0000")) { log_message('error',"iPayLinks payment failed! error code:".$respObject->resultCode."; result Msg: ".$respObject->resultMsg.'; orderId:'.$respObject->orderId.'; dealId:'.$respObject->dealId."; From: ".$ref); } $ret->check = true; return $ret; } /*! * 转换字符集编码 * @param $data * @param $targetCharset * @return string */ protected function characet($data, $targetCharset) { if (!empty($data)) { $fileType = "UTF-8"; if (strcasecmp($fileType, $targetCharset) != 0) { $data = mb_convert_encoding($data, $targetCharset, $fileType); // $data = iconv($fileType, $targetCharset.'//IGNORE', $data); } } return $data; } protected function curl($url, $postFields = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $postBodyString = ""; if (is_array($postFields) && 0 < count($postFields)) { foreach ($postFields as $k => $v) { if ("@" != substr($v, 0, 1)) //判断是不是文件上传 { $postBodyString .= "$k=" . urlencode($this->characet($v, "UTF-8")) . "&"; } } unset($k, $v); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1)); } $headers = array('content-type: application/x-www-form-urlencoded;charset=UTF-8'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $reponse = curl_exec($ch); if (curl_errno($ch)) { log_message('error', " iPayLinks curl error code: ".curl_error($ch)."; curl postBodyString: ".substr($postBodyString, 0, -1)); } else { $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (200 !== $httpStatusCode) { log_message('error', " iPayLinks Request html Status Code: ".$error_message."; curl postBodyString: ".substr($postBodyString, 0, -1)); } } curl_close($ch); return $reponse; } /*! * 检验非空 * @author LYT * @date 2017-08-17 * @param [type] $value [description] * @return boolean true-空;false-非空 */ protected function checkEmpty($value) { if (!isset($value)) return true; if ($value === null) return true; if (trim($value) === "") return true; return false; } /*! * [result_to_return_url description] * 返回 和其他支付方式统一 的结果给支付结果页面 * @author LYT * @date 2017-08-28 * @param [type] $code [description] * @return [type] [description] */ protected function result_2_return_url($code,$msg) { $ret['code'] = 0; $ret['msg'] = ""; $ret['error_code'] = $code ? $code : "Unknow"; $ret["error_code"] .= "."; $tmp_msg = $msg ? strstr($msg,":",true)."." : false; // result msg的英文部分 $code_msg = $tmp_msg ? $tmp_msg : "Please contact your advisor."; $ret['error_code'] .= $code_msg; switch ($code) { case '0000': $ret['code'] = 0; $ret['msg'] = "success"; break; default: $ret['code'] = $code; $ret['msg'] = "Payment Failed."; break; } return $ret; } protected function create_guid() { return strtolower(md5(uniqid(mt_rand(), true))); } protected function payment_status() { return array( 0 => "Denied", 1 => "Pending", 2 => "Payment success", 3 => "Denied" ); } //获取note详情,以便后续修改各项数据 public function note_modal($pn_txn_id = false, $pn_invoice = false ,$notice_time = false) { $data = array(); $data['IPL_orderId'] = $pn_invoice; if (!empty($pn_txn_id)) { $data['note'] = $this->Note_model->note($pn_txn_id); if (!empty($data['note'])) { if (!empty($pn_invoice)) { $orderid_info = $this->analysis_orderid($pn_invoice); } else { $orderid_info = $this->analysis_orderid($data['note']->IPL_orderId); } if (!empty($orderid_info)) { $orderid_info = json_decode($orderid_info); $data['order_info'] = $this->IPayLinks_model->get_order($orderid_info->orderid, true, $orderid_info->ordertype); } $data["paytext"] = $this->payment_status(); echo json_encode($this->load->view('note_setting', $data, true)); return true; } } echo json_encode('没找到数据!'); return; } public function note_order_modal($old_order,$pn_invoice = false ,$notice_time = false) { $data = array(); $data['IPL_orderId'] = $pn_invoice; if (!empty($pn_invoice)) { $data['note'] = $this->Note_model->note_order($old_order,$notice_time); if (!empty($data['note'])) { if (!empty($pn_invoice)) { $orderid_info = $this->analysis_orderid($pn_invoice); } else { $orderid_info = $this->analysis_orderid($data['note']->IPL_orderId); } if (!empty($orderid_info)) { $orderid_info = json_decode($orderid_info); $data['order_info'] = $this->IPayLinks_model->get_order($orderid_info->orderid, true, $orderid_info->ordertype); } $data["paytext"] = $this->payment_status(); echo json_encode($this->load->view('note_setting', $data, true)); return true; } } echo json_encode('没找到数据!'); return; } //关闭note通知,用于手动处理通知后 public function close_note($pn_txn_id) { $data = array(); $data['note'] = $this->Note_model->note($pn_txn_id); if (!empty($data['note'])) { $this->Note_model->update_send($pn_txn_id, 'send'); echo json_encode('通知已经关闭!'); return true; } echo json_encode('没找到数据!'); return; } //修改订单名 public function note_modal_save() { $data = array(); $pn_txn_id = $this->input->post('pn_txn_id'); $pn_invoice = $this->input->post('pn_invoice'); if (!empty($pn_txn_id) && !empty($pn_invoice)) { $orderid_info = $this->analysis_orderid($pn_invoice); if (!empty($orderid_info)) { $orderid_info = json_decode($orderid_info); $advisor_info = $this->IPayLinks_model->get_order($orderid_info->orderid, false, $orderid_info->ordertype); if (!empty($advisor_info)) { $this->Note_model->set_invoice($pn_txn_id, $pn_invoice); $this->batch_send_note($pn_txn_id); echo json_encode('修改成功!'); return true; } } } echo json_encode('没找到数据!'); return; } //用于HT--交易详情 public function receipt($pm_transaction_id) { if ( ! $pm_transaction_id) { return false; } $data = array(); $data = $this->Note_model->note($pm_transaction_id); $this->load->view('receipt_mail', $data); } }