Apijd.php 3.16 KB
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: JY
 * Date: 2015-09-23
 */

namespace app\home\controller;
use app\home\logic\UsersLogic;
use think\Db;
use think\Exception;
use think\Session;
use think\Controller;
use think\Verify;
use think\Cookie;
use think\Page;
class Apijd extends Controller
{


    public function _initialize()
    {
        Session::start();
    }
    /*更新第三方平台token*/
    public function callback()
    {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }
        $getcode=I('code');
        $gettoken=I('token');

     //   $gettoken="{\"token\":\"08887fc3-5270-494a-95bb-e3702a7e29cd\",\"expires_in\":\"31104000\",\"time\":\"1543301262378\",\"user_nick\":\"seasib\",\"venderId\":\"334040\"}";

        if ($gettoken) {
            $gettoken1 = json_decode($gettoken, true);
            $data['token'] = $gettoken1['token'];
            $data['expires_in'] = $gettoken1['expires_in'];
            $data['time'] = $gettoken1['time'];
            $data['user_nick'] = $gettoken1['user_nick'];
            $res = M('jd_store')->where(array('venderId' => $gettoken1['venderId']))->find();
            if ($res) {
                M('jd_store')->where(array('venderId' => $gettoken1['venderId']))->save($data);
            } else {
                $data['venderId'] = $gettoken1['venderId'];
                M('jd_store')->save($data);
            }
            $jsonres["code"] = 0;
            $jsonres["msg"] = "success";
            $jsonres["data"] = "";

            return json_encode($jsonres);
        }

    }

    //根据账套
    public  function  jdstoreinfo()
    {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }
     //   $postStr="{\"accdb\":\"ppt\"}";
        if (empty($postStr))
        {
            $jsonres["code"] = -1;
            $jsonres["msg"] = "无法获取入参";
            $jsonres["data"] = "";
            return json_encode($jsonres);
        }
        $postStr=json_decode($postStr,true);
        $res=M('jd_store')->where(array('accdb'=>$postStr['accdb']))->find();
        if (empty($res))
        {
            $jsonres["code"] = -1;
            $jsonres["msg"] = "该账套未授权";
            $jsonres["data"] = "";
            return json_encode($jsonres);
        }
        $jsonres["code"] = 0;
        $jsonres["msg"] = "ok";
        $jsonres["data"] = json_encode($res);
        return json_encode($jsonres);
    }


}