创建类demo(PHP)

测试环境系统参数及接口调用地址:

$sid         = 'apidev2';
$appkey      = 'xxx2test';
$appsecret   = '12345';

$service_url = 'http://121.41.177.115/openapi2/trade_push.php';
/*trade_query.php此为接口名示例,根据实际对接的接口进行变更*/

正式环境系统参数及接口调用地址:

$sid         = '卖家帐号';
$appkey      = '卖家账号-ot 或 卖家账号-gw';
$appsecret   = 'xxxxxx';
/*appsecret销售向公司申请后提供给商家*/

 $service_url = 'http://121.41.177.115/openapi2/trade_push.php';
/*trade_query.php此为接口名示例,根据实际对接的接口进行变更*/

创建类demo(PHP)

<?php
//打包参数
function packData(&$req)
{
    ksort($req);
    $arr = array();
    foreach($req as $key => $val)
    {
        if($key == 'sign') continue;
        if(count($arr))
            $arr[] = ';';
        $arr[] = sprintf("%02d", iconv_strlen($key, 'UTF-8'));
        $arr[] = '-';
        $arr[] = $key;
        $arr[] = ':';
        $arr[] = sprintf("%04d", iconv_strlen($val, 'UTF-8'));
        $arr[] = '-';
        $arr[] = $val;
    }
    return implode('', $arr);
}
//加密生成sign
function makeSign(&$req, $appsecret)
{
    $sign = md5(packData($req) . $appsecret);
    $req['sign'] = $sign;
}
//发送请求
function wdtOpenApi($req,$appsecret, $url)
{
    makeSign($req, $appsecret);
    $postdata = http_build_query($req);
    $length   = strlen($postdata);
    $cl       = curl_init($url);
    curl_setopt($cl, CURLOPT_POST, true);
    curl_setopt($cl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
    curl_setopt($cl,CURLOPT_HTTPHEADER,array("Content-Type: application/x-www-form-urlencoded","Content-length: ".$length));
    curl_setopt($cl,CURLOPT_POSTFIELDS,$postdata);
    curl_setopt($cl,CURLOPT_RETURNTRANSFER,true);
    $content = curl_exec($cl);
    if (curl_errno($cl))
    {
        echo "Error: " . curl_error($cl);
    }
    curl_close($cl);
    $json = json_encode(json_decode($content));
    if(!$json)
    {
        var_dump($content);
        return NULL;
    }
    return $json;
}

$sid         = 'apidev2';
$appkey      = 'xxx2test';
$appsecret   = '12345';

$service_url = 'http://121.41.177.115/openapi2/trade_push.php';


$no         = '123456543';
$now_time   = date('Y-m-d h:i:s');
$trade_list = array();
$dis        = 0;//优惠
$price2     = 39;//单价
$num2       = 5;//数量
$dis2       = 0;//优惠
$post       = 0;//邮费

$paid = ($price2*$num2)-$dis-$dis2+$post;

$trade_list[] = array
(
    'tid'             => 'LTEST'.$no,
    'trade_status'    => 30,
    'delivery_term'   => 1,
    'pay_status'      => 2,
    'trade_time'      => $now_time,
    'pay_time'        => $now_time, // 未付款情况下为0000-00-00 00:00:00
    'buyer_nick'      => '',
    'buyer_email'     => '123456234533@mail.com',
    'receiver_mobile' => '13233456110',
    'receiver_telno'  => '1234563567',
    'receiver_zip'    => '0000000',
    'receiver_province'=>'北京',
    'receiver_name'=>'亚历山大',
    'receiver_city'=>'北京市',
    'receiver_district'=>'海淀区',
    'receiver_address'=>'海淀',
    'logistics_type'  => 4, // ems
    'invoice_type'    => 0,
    'invoice_title'   => '',
    'invoice_content' => '发票内容+',
    'buyer_message'   => '发最好&&&的+',
    'cust_data'       => '72-500.0;84-368.0;67-258.0;65-99.0;87-158.0;',
    'seller_memo'          => '测试专用',
    'seller_flag'     => 1,
    'post_amount'     => $post, //邮费
    'paid'            => $paid, //已支付金额
    'cod_amount'      => '0',
    'ext_cod_fee'     => '0',
//    'warehouse_no'    =>'api_test',(非自动流转模式该字段不要传)
//    'is_auto_wms'   => 0,(非自动流转模式该字段不要传)
//    'wms_type'          => 2,(非自动流转模式该字段不要传)
    'order_list'      => array(
        array
        (
            'oid'            => 'LTEST'.$no,
            'status'         => 30,
            'refund_status'  => 0,
            'goods_id'       => 'E166D18BAAEA420CB132E105B3B6128A',
            'spec_id'        => '',
            'goods_no'       => '',
            'spec_no'        => '9787533951092',
            'goods_name'     => '情商是什么?——关于生活智慧的44个故事',
            'spec_name'      => '',
            'num'            => $num2,
            'price'          => $price2,
            'adjust_amount'  => '0', //手工调整,特别注意:正的表示加价,负的表示减价
            'discount'       => $dis2, //子订单折扣
            'share_discount' => '0', //分摊优惠
            'cid'            => '13',
        )
    )
);
//请求参数
$req = array
(
    'sid'        => $sid,
    'appkey'     => $appkey,
    'timestamp'  => time(),
    'shop_no'    => 'api_test',
    'switch'     => 0, // 0为非严格模式  1为严格模式
    'trade_list' => json_encode($trade_list, JSON_UNESCAPED_UNICODE)
);
$json = wdtOpenApi($req, $appsecret, $service_url);
var_dump($json);
Print Friendly, PDF & Email