刚来公司不久老板要求要开发一个电商平台类似O2O那样的,三个月左右的时间平台开发的差不多就剩接口,其中我负责的是跟C#程序员对接发货,
话不多说直接上代码。变量是从数据库查的字段
$json = '{
"lngemployeeid": "'.$list["lngemployeeid"].'",
"PingTai": "'.$list["platform"].'",
"OrderNumber": "'.$list["order_no"].'",
"OrderTime": "'.$list["created_at"].'",
"PeiSongTime":"'.$list2["date"].'",
"PeiSongFangShi":"'.$list2["type"].'",
"OrderMoney":"'.$list["payment_fee"].'",
"FukuanFangShi": "'.$list["pay_type"].'",
"ToPayMoney": "'.$list["product_fee"].'",
"MoneyCode": "",
"Email": "'.$list["email"].'",
"Remark": "'.$list["remark"].'",
"YunFei": "'.$list2["money"].'",
"DpName": "'.$list["DpName"].'",
"StockId": "'.$list["StockId"].'",
"Address": {
"Email":"'.$list["email"].'",
"Name": "'.$list1["name_info"].'",
"Phone": "'.$list1["shouhuo_phone"].'",
"PostCode":"'.$list1["zip_code"].'",
"Province":"'.$list1["city"].'",
"Address1":"'.$list1["street"].'",
"Address2":"'.$list1["town"].'"
},
"Item": ['.$itemList.'],
"Fujia": {
"Paizhao": "'.$list["Paizhao"].'",
"WxTiebiao":"'.$list["WxTiebiao"].'",
"WxFile":"'.$list["WxFile"].'",
"SpTiebiao":"'.$list["SpTiebiao"].'",
"SpFile":"'.$list["SpFile"].'",
"LpBaoz":"'.$list["LpBaoz"].'",
"EcBaoz":"'.$list["EcBaoz"].'",
"SpBaoxian":"'.$list["SpBaoxian"].'",
"YfBaoxian":"'.$list["YfBaoxian"].'",
"LingShou": {
"Money": "'.$list4["price"].'",
"KehuName": "'.$list4["name"].'",
"ItemName": "'.$list4["message"].'"
},
"ZxcFanshou": {
"Fshoud":"'.$list["Fshoud"].'",
"FshouTime":"'.$list["FshouTime"].'",
"ItemName":"'.$list["ItemName"].'",
"CheBhao":"'.$list["CheBhao"].'",
"CheZhong":"'.$list["CheZhong"].'",
"Chicun":"'.$list["Chicun"].'",
"Color":"'.$list["Color"].'",
"Dianyuan":"'.$list["Dianyuan"].'"
},
"YfDaofu":"'.$list["YfDaofu"].'",
"ByXchuan":"'.$list["ByXchuan"].'",
"YcFahuodizhi":"'.$list["YcFahuodizhi"].'",
"DyNps":"'.$list["DyNps"].'",
"NpsFile":"'.$list["NpsFile"].'",
"DyQqs":"'.$list["DyQqs"].'",
"QqsFile":"'.$list["QqsFile"].'",
"DyJjs":"'.$list["DyJjs"].'",
"JjsFile":"'.$list["JjsFile"].'",
"Weixiu":"'.$list["Weixiu"].'",
"Baofei":"'.$list["Baofei"].'"
}
}';
$post_data = array('Order' => $json);
$ch = curl_init('http://www.xxx.xxx:xxxx/Inner/OrderOut.ashx');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$str = substr($result,0,strpos($result,'<br />接收的值'));
// echo '<pre>';
// print_r($result);
// die();
return ['status'=>$str];
他要的格式基本就是这样的,返回OK就说明成功,返回别的说明失败了并且保存数据库,上面是控制器的代码,下面是前端的代码
function fahuo(obj, id) {
(function($) {
$.getUrlParam = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return 0;
}
})(jQuery);
var a = $.getUrlParam('status');
if (a == 2 || a == 0) {
var order = $('.order_no').attr('data-no');
$.ajax({
type: "POST",
url: "{:url('order/transmit')}",
data: {
orderId: id,
order_no: order,
},
dataType: 'json',
success: function(data) {
//处理发货返回来的信息
var i = data.status;
var j = i.indexOf('OK');
var l = i.indexOf('此订单已发货!');
// console.log(i);
// var j = i.match(/(S*)<br />/)[1];
// var j = i.match(/(S*)
/)[1];
if ((j >= 0) || (l >= 0)) {
$.ajax({
type: "POST",
url: "{:url('order/shipping')}",
data: {
orderId: id,
},
dataType: 'json',
success: function(res) {
if (res.status == 1) {
layer.msg(res.message, {
icon: 1,
time: 2000
});
setTimeout('location.reload()', 1000);
}
}
});
} else {
alert(i);
}
}
});
// console.log(b);
}
}