当使用钱海支付通道进行支付成功之后,如果订单发货后则变更为completed,这个时候需要把对应订单的物流单号及平台上传到钱海后台,这样才能允许该笔订单资金的提取。没有这个运单号或者失败,则无法代表发货了或者客户收到货,在处理争议以及处理提现的时候都会出现问题。
而上传物流单号则是通过物流的api上传的,经过研究得出一下示例代码,具体如下:
<?php
/*
表sales_flat_order新加状态字段logitstatu,默认是0
ALTER TABLE `sales_flat_order` ADD COLUMN `logitstatu` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'oc_shipping';
*/
set_time_limit(0);
$dir = dirname(dirname(__FILE__));
require_once($dir .'/app/Mage.php');
//require_once($dir .'/vendor/autoload.php');
umask(0);
Mage::app();
define("ACCOUNT", "****");
define("TERMINAL", "****");
define("SECURE_CODE", "****");
define("BILL_API", "https://query.oceanpayment.com/service/check/normal");
define("OC_API", "https://query.oceanpayment.com/service/uploadTrackingNo");
$read =Mage::getSingleton("core/resource")->getConnection('core_read');
$write=Mage::getSingleton("core/resource")->getConnection('core_write');
$datetimes=date('Y-m-d',strtotime("-30 day"));
$datetimes="2018-12-25 00:00:00";
$sql="SELECT a.entity_id,a.increment_id,a.logitstatu,b.parent_id,b.method FROM `sales_flat_order` as a LEFT JOIN `sales_flat_order_payment` as b ON a.entity_id=b.parent_id WHERE a.logitstatu=0 AND a.created_at>'{$datetimes}' AND a.status='complete' AND b.method='oceanpayment_creditcard' ORDER BY a.entity_id ASC;";
$result=$read->fetchAll($sql);
foreach($result as $k=>$v){
$singValue=ACCOUNT.TERMINAL.$v['increment_id'].SECURE_CODE;
$singValue=hash("sha256", $singValue);
$ordata=array(
"account" =>ACCOUNT,
"terminal" =>TERMINAL,
"signValue" => $singValue,
"order_number" =>$v['increment_id']
);
$arr = curl_post($ordata,BILL_API);
if($arr["paymentInfo"]["payment_id"]){
//根据订单号查询物流单号
$pid=$read->fetchAll("SELECT track_number FROM `sales_flat_shipment_track` WHERE `order_id`=".$v['entity_id']);
//$order=get_object_vars($pid);
$tracknumber=$pid['0']['track_number'];
if($tracknumber){
//获取唯一支付ID
$payment_id=$arr["paymentInfo"]["payment_id"];
if(strlen($tracknumber)==12){
$tracking_site="http://www.sf-express.com/us/en/dynamic_function/waybill/#search/bill-number/";
}else{
$tracking_site="https://www.17track.net/en#nums";
}
$tracking_handle="cherry";
$values=ACCOUNT.TERMINAL.$payment_id.$tracknumber.$tracking_site.$tracking_handle.SECURE_CODE;
$singValue=hash("sha256", $values);
$data=array(
"account" => ACCOUNT,
"terminal" => TERMINAL,
"signValue" => $singValue,
"payment_id" => $payment_id,
"tracking_number" => $tracknumber,
"tracking_site" => $tracking_site,
"tracking_handler" => $tracking_handle
);
$arr = curl_post($data,OC_API);
$tracking_results=$arr["tracking_results"];
if ($tracking_results != 1) {
file_put_contents("oc_shipping_log.txt",date("Y-m-d H:i:s")." order:{$v['increment_id']} "."fail"."\r\n",FILE_APPEND);
}else{
//上传成功更改状态
$sql="update sales_flat_order set logitstatu=1 where entity_id=".$v['entity_id'];
$write->query($sql);
file_put_contents("oc_shipping_log.txt",date("Y-m-d H:i:s")." order:{$v['increment_id']} "."success"."\r\n",FILE_APPEND);
echo "OK:".$v['increment_id']."\r\n";
}
}
}
sleep(3);
}
function curl_post($ordata,$url){
//调用curl方法
$ch = curl_init();
//设置抓取的url
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($ordata));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
curl_close($ch);
if (curl_errno($ch)) {
$txt = date("Y-m-d H:i:s").'Curl Error:'.curl_error($ch);//捕抓异常
//异常数据写入日志
file_put_contents("curl_error.txt",date("Y-m-d H:i:s")."\n捕抓异常".$txt,FILE_APPEND);
exit;
}else{
$apiobj=simplexml_load_string($response);
$response=json_encode($apiobj);
$response=json_decode($response,true);
//file_put_contents("curl_error.txt",date("Y-m-d H:i:s")."\n".json_encode($response['paymentInfo']),FILE_APPEND);
return $response;
}
}
?>
说明:***是钱海给的账户号及秘钥。该文件基于magento1.9开发,使用方式为防止在网站目录下的shell文件夹下,然后启动定时任务执行即可。成功后会给该笔订单增加标记,方便下一次查询的时候不再执行。其他系统的原理类似,只要更换里面的部分写法即可。
今天的文章快递订单生成器_快递订单生成器分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/89368.html