diff --git a/webht/third_party/pay/config/iPayLinks.php b/webht/third_party/pay/config/iPayLinks.php index 594624ef..7de2b398 100644 --- a/webht/third_party/pay/config/iPayLinks.php +++ b/webht/third_party/pay/config/iPayLinks.php @@ -17,6 +17,7 @@ $config['currencyCode'] = "USD"; $config['travDetailsSize'] = "0"; $config['pkey'] = "30819f300d06092a864886f70d010101050003818d00308189028181008c903972be5509375edec0d6793d8d3eb533334d146069b5dfcdafd24e5c7d0a05d1774488ea257d504a18c9098d798c0f523f3ad722e3e9c32ae7fecd7e734b340b9c8ff805aa32d0a49cb6df9eca3bb6954d966f6148533a8d667aabb55b2762dcd06308c94d24d257dfdb2ad86b46702774c51e7627e5b707d52224ef794b0203010001"; // 商户证书的公钥 -$config['queryUrl'] = "https://query.ipaylinks.com/webgate/orderQuery.htm"; +// $config['queryUrl'] = "https://query.ipaylinks.com/webgate/orderQuery.htm"; +$config['queryUrl'] = "https://query-aw.ipaylinks.com/webgate/orderQuery.htm"; // 国内 $config['query_mode'] = "1"; $config['query_type'] = "1"; diff --git a/webht/third_party/pay/controllers/iPayLinksService.php b/webht/third_party/pay/controllers/iPayLinksService.php index 9e6b2a84..ec19d471 100644 --- a/webht/third_party/pay/controllers/iPayLinksService.php +++ b/webht/third_party/pay/controllers/iPayLinksService.php @@ -340,7 +340,7 @@ class IPayLinksService extends CI_Controller } //退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理 - if ($item->IPL_payType == 'Refunded') { + if ($item->IPL_payType == 'refund') { $this->Note_model->update_send($item->IPL_dealId, 'send'); continue; } @@ -689,7 +689,7 @@ class IPayLinksService extends CI_Controller * @date 2017-08-17 * @param mix $resp API返回的原始xml或异步返回的post数组 */ - protected function verify_sign($resp=NULL) + protected function verify_sign($resp=NULL, $sign=true) { $ret = new ArrayObject(); $ret->check = false; @@ -710,20 +710,21 @@ class IPayLinksService extends CI_Controller 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); + if ($sign === true) { + $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; @@ -776,7 +777,7 @@ class IPayLinksService extends CI_Controller } 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)); + log_message('error', " iPayLinks Request html Status Code: ".$httpStatusCode."; curl postBodyString: ".substr($postBodyString, 0, -1)); } } curl_close($ch); @@ -954,4 +955,91 @@ class IPayLinksService extends CI_Controller var_dump($ssje); } + /*! + * 每天请求一次,批量取回退款记录保存 + * @author LYT + * @date 2017-11-06 + */ + public function get_refund_list($daylength=3) + { + bcscale(2); + $ret = array(); + $list = $this->refund_list_info($daylength); + foreach ($list as $key => $refund) { + if ($refund->stateCode == 1) continue; + $ret[] = $this->Note_model->save_refund( + strval($refund->dealId) + , strval($refund->orderId) + , strval("-" . bcdiv(floatval($refund->refundAmount), 100)) + , strval(date('Y-m-d H:i:s',strtotime($refund->refundTime))) + , strval(date('Y-m-d H:i:s',strtotime($refund->completeTime))) + , $refund->stateCode + , "0000" + , json_encode($refund) + , "refund" + ); + } + echo "Got record count: " . count($ret); + return; + } + + /*! + * 批量取回退款记录 + * @author LYT + * @date 2017-11-03 + */ + public function refund_list_info($daylength) + { + $this->query_info_arr["queryOrderId"] = $this->create_guid(); + $this->query_info_arr['mode'] = '2'; + $this->query_info_arr['type'] = '2'; + $this->query_info_arr["beginTime"] = date('Ymd000000', strtotime("-$daylength days")); + $this->query_info_arr["endTime"] = date('Ymd235959'); + $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, false); + + // 未得到结果 + if (false === $query_resp->data) { + // echo "No record."; + return false; + } + $refund_list = $query_resp->data->refundDetails->detail; + foreach ($refund_list as $key => $refund) { + // 由于ipaylinks批量查询的bug,这里要用单笔查询校对 + $this_info = $this->get_refund($refund->refundOrderId); + if ($this_info !== false) { + $refund->stateCode = $this_info->stateCode; + $refund->refundTime = $this_info->refundTime; + $refund->completeTime = $this_info->completeTime; + } + } + return $refund_list; + } + + /*! + * 单笔查询退款信息 + * ipaylinks的批量查询有问题,所以这个需要用单笔查询确认信息 + * @author LYT + * @date 2017-11-06 + * @param string $refund_order_id 退款信息中的refundOrderId + */ + public function get_refund($refund_order_id) + { + $this->query_info_arr["queryOrderId"] = $this->create_guid(); + $this->query_info_arr["orderId"] = $refund_order_id; + $this->query_info_arr['mode'] = '1'; + $this->query_info_arr['type'] = '2'; + $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, false); + // 未得到结果 + if (false === $query_resp->data) { + return false; + } + return $query_resp->data->refundDetails->detail; + } + } diff --git a/webht/third_party/pay/models/note_model.php b/webht/third_party/pay/models/note_model.php index efe06ff0..a9745543 100644 --- a/webht/third_party/pay/models/note_model.php +++ b/webht/third_party/pay/models/note_model.php @@ -70,7 +70,8 @@ class Note_model extends CI_Model { $search_key = trim($search_key); if (!empty($search_key)) { $search_sql.=" AND ( pn.IPL_dealId = '$search_key' - OR pn.IPL_orderId like '%$search_key%' )"; + OR pn.IPL_orderId like '%$search_key%' + OR pn.IPL_memo like '%$search_key%' )"; } $this->search = $search_sql; return $this->get_list(); @@ -190,4 +191,46 @@ class Note_model extends CI_Model { return $this->INFO->query($sql, array($stateCode,$payAmount,$dealId)); } + public function save_refund($dealId, $orderId, $refundAmount, $refundTime, $completeTime, $stateCode, $resultcode, $memo, $paytype) + { + $sql = "IF NOT EXISTS( + SELECT TOP 1 1 + FROM IPayLinksLog + WHERE IPL_dealId = ? + ) + INSERT INTO IPayLinksLog + ( + IPL_dealId + ,IPL_orderId + ,IPL_orderAmount + ,IPL_stateCode + ,IPL_acquiringTime + ,IPL_completeTime + ,IPL_memo + ,IPL_sent + ,IPL_noticeTime + ,IPL_payType + ,IPL_resultCode + ) + VALUES + ( + ?,?,?,?,?,?,?,'send',?,?,? + ) + "; + $query = $this->INFO->query($sql, + array($dealId + ,$dealId + ,$orderId + ,$refundAmount + ,$stateCode + ,$refundTime + ,$completeTime + ,$memo + ,$completeTime + ,$paytype + ,$resultcode + )); + return $query; + } + } diff --git a/webht/third_party/pay/views/iPayLinks_list.php b/webht/third_party/pay/views/iPayLinks_list.php index dd33dfaf..35e291f7 100644 --- a/webht/third_party/pay/views/iPayLinks_list.php +++ b/webht/third_party/pay/views/iPayLinks_list.php @@ -115,8 +115,11 @@
  • - IPL_payerName; ?>
    - IPL_payerEmail; ?> + IPL_payType == 'refund') { + echo "退款"; + } else { + echo $item->IPL_payerName . "
    " . $item->IPL_payerEmail; + } ?>
  • IPL_dealId; ?>