PHP 对接管易ERP

//获取店铺信息
    function getShops()
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.shop.get';
        $data['page_no'] = '1';
        $data['page_size'] = '100';
        $data['sign'] = $this->sign($data, SECRET);
        $this->success('成功', json_decode($this->mycurl(URL, $data)));
    }

// 会员查询
    function getVip($code)
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.vip.get';
        $data['code'] = $code;
        $data['sign'] = $this->sign($data, SECRET);
        $Rult = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
        return $Rult['total'];
    }

    // 会员新增
    function addVip($UnionID, $Nickname)
    {
        Log::init([
            'path' => LOG_PATH . 'GuanYiRegisterError',
            'type' => 'file'
        ]);
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.vip.add';
        //会员代码
        $data['code'] = $UnionID;
        //会员名称
        $data['name'] = $Nickname;
        //所属店铺
        $data['shop_code'] = 'ZCZXCX';
        //地址列表
        $receive_infos = array();
        $receive_infos[] = array(
            //名称
            'name' => '地址',
            //收货人
            'receiver' => $Nickname,
            //收获手机
            'mobile' => 18888888888,
            //收货详细地址
            'address' => '中国'
        );
        $data['receive_infos'] = $receive_infos;
        $data['sign'] = $this->sign($data, SECRET);
        $Rult = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
        if ($Rult['success'] == false) {
            Log::write($UnionID);
            Log::write($Nickname);
            dump($Rult);
            $this->error('授权网络超时');
        }
    }

//获取仓库信息
    function getWarehouses()
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.warehouse.get';
        $data['page_no'] = '1';
        $data['page_size'] = '10';
        // $data['code'] = '001';
        $data['sign'] = $this->sign($data, SECRET);
        $this->success('成功', json_decode($this->mycurl(URL, $data)));
    }

// 商品查询
    function getGoods()
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.items.get';
        $data['page_no'] = '1';
        $data['page_size'] = '10';
        // $data['code'] = 'ZZLN000005';
        $data['sign'] = $this->sign($data, SECRET);
        $this->success('成功', json_decode($this->mycurl(URL, $data)));
    }


//获取订单 $OrderSn 平台单号
    public function getOrders($OrderSn)
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.trade.get';
        $data['platform_code'] = $OrderSn;
        // $date['receiver_mobile']='15928552965';
        $data['sign'] = $this->sign($data, SECRET);
        $Array = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
        //验证
        if (empty($Array['orders'])) {
            $this->error('获取订单失败:平台单号' . $OrderSn);
        }
        $delivery_state = $Array['orders'][0]['delivery_state'];
        $refund = $Array['orders'][0]['details'][0]['refund'];
        $platform_code = $Array['orders'][0]['platform_code'];
        if (!empty($Array['orders'][0]['deliverys'])) {
            $express_name = $Array['orders'][0]['deliverys'][0]['express_name'];
            $express_code = $Array['orders'][0]['deliverys'][0]['express_code'];
            $mail_no = $Array['orders'][0]['deliverys'][0]['mail_no'];
        } else {
            $express_name = '';
            $express_code = '';
            $mail_no = '';
        }
        $Return = [
            //发货状态 0-未发货//1-部分发货//2-全部发货
            'delivery_state' => $delivery_state,
            //平台单号
            'platform_code' => $platform_code,
            //快递公司名称
            'express_name' => $express_name,
            //快递公司代码
            'express_code' => $express_code,
            //快递单号
            'mail_no' => $mail_no
        ];
        $Json = json_encode($Return);
        return $Json;
    }


//新增订单
    function addOrder($OrderSn, $OrderTime, $PayTime, $UnionID, $Name, $Mobile, $Address, $Province, $City, $District, $details, $Money, $PayOrder)
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.trade.add';
        //订单类型 //Sales-销售订单//Return-换货订单//Charge-费用订单//Delivery-补发货订单//Invoice-补发票订单
        $data['order_type_code'] = 'Sales';
        //退款状态 //0:未退款//1:退款完成//2:退款中
        $data['refund'] = 0;
        $data['oid'] = $OrderSn;
        //店铺代码
        $data['shop_code'] = 'ZCZXCX';
        //平台单号
        $data['platform_code'] = $OrderSn;
        //下单时间
        $data['deal_datetime'] = $OrderTime;
        //支付时间
        $data['pay_datetime'] = $PayTime;
        //会员代码
        $data['vip_code'] = $UnionID;
        //买家留言
        $data['buyer_memo'] = '';
        //收货人
        $data['receiver_name'] = $Name;
        $data['receiver_mobile'] = $Mobile;
        $data['receiver_address'] = $Address;
        $data['receiver_province'] = $Province;
        $data['receiver_city'] = $City;
        $data['receiver_district'] = $District;
        $data['details'] = $details;
        $payments = array();
        $payments[] = array(
            //支付放视
            'pay_type_code' => 'WechatPay',
            //支付金额
            'payment' => $Money,
            //交易号
            'pay_code' => $PayOrder,
            //支付时间
            'paytime' => $PayTime
        );
        $data['payments'] = $payments;
        $invoices = array();
        $invoices[] = array(
            //发票部分
            'invoice_type' => 1,
            'invoice_title' => '个人',
        );
        $data['invoices'] = $invoices;
        $data['sign'] = $this->sign($data, SECRET);
        $Rult = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
        if ($Rult['success'] == false) {
            $this->error('失败');
        }
    }

    /*Config*/
    function mycurl($url, $data)
    {
        $data_string = $this->json_encode_ch($data);
        $data_string = urlencode($data_string);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type:text/json;charset=utf-8',
            'Content-Length:' . strlen($data_string)
        ));
        $content = curl_exec($ch);
        curl_close($ch);
        return $content;
    }

    function sign($data, $secret)
    {
        if (empty($data)) {
            return "";
        }
        unset($data['sign']); //可选,具体看传参
        $data = $this->json_encode_ch($data);
        $sign = strtoupper(md5($secret . $data . $secret));
        return $sign;
    }

    function json_encode_ch($arr)
    {
        return urldecode(json_encode($this->url_encode_arr($arr)));
    }

    function url_encode_arr($arr)
    {
        if (is_array($arr)) {
            foreach ($arr as $k => $v) {
                $arr[$k] = $this->url_encode_arr($v);
            }
        } elseif (!is_numeric($arr) && !is_bool($arr)) {
            $arr = urlencode($arr);
        }
        return $arr;
    }

    //获取订单oid
    public function GetOrderOid($OrderSn)
    {
        $data = array();
        $data['appkey'] = APPKEY;
        $data['sessionkey'] = SESSIONKEY;
        $data['method'] = 'gy.erp.trade.get';
        $data['platform_code'] = $OrderSn;
        // $date['receiver_mobile']='15928552965';
        $data['sign'] = $this->sign($data, SECRET);
        $Array = json_decode(json_encode(json_decode($this->mycurl(URL, $data))), true);
        //验证
        if (empty($Array['orders'])) {
            $this->error('获取订单失败:平台单号' . $OrderSn);
        }
        return $Array['orders'][0]['details'][0]['oid'];
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值