php京东授权,京东jos 获取授权及php-sdk的使用示例

<?phpnamespaceM \Controller;useCommon\Model\JosModel;useThink\Controller;/*红酒奖励 控制器*/classJosControllerextendsController {private$app_key;//应用的app_keyprivate$app_secret;//即创建应用时的Appsecret(从JOS控制台->管理应用中获取)private$expires_in;//失效时间(从当前时间算起,单位:秒)private$access_token;//JOS 所回传的access_token值private$refresh_token;//即授权时获取的刷新令牌private$time;//授权的时间点(UNIX时间戳,单位:毫秒)private$jd_client;private$server_url;public function__construct(){Vendor('Jos.jd.JdClient');$model=newJosModel();$res=$model->getData();$info=$res[0];$this->app_key=$info['app_key'];$this->app_secret=$info['app_secret'];$this->expires_in=$info['expires_in'];$this->access_token=$info['access_token'];$this->refresh_token=$info['refresh_token'];$this->time=$info['time'];$this->jd_client=new\JdClient();$this->server_url="https://api.jd.com/routerjson";}public functionoauth(){$code=$_GET['code'];$appKey='DExxxxxxxxxxxxxxxxxxxxxx83';$appSecret='40xxxxxxxxxxxxxxxxxxxxxxxxx31';$url="http://www.xxxx.com/m/Jos/oauth.html";$toUrl="https://oauth.jd.com/oauth/token?grant_type=authorization_code&client_id=".$appKey."&client_secret=".$appSecret."&scope=read&redirect_uri=".$url."&code=".$code."&state=1234";if(!$code){//数据处理 此处其实是无法处理数据的,你问我,我问谁去啊?!!!echo'hahahahhahahahah';}else{header("Location:".$toUrl);}}public functiontest(){$appKey='DExxxxxxxxxxxxxxxxxxxxxx83';$url='http://www.xxxx.com/m/Jos/oauth.html';$toUrl='https://oauth.jd.com/oauth/authorize?response_type=code&client_id='.$appKey.'&redirect_uri='.$url.'&state=123';header("Location:".$toUrl);}/*** 将获取到的token等信息 添加到数据库 下面的为获取的其中一次数据 注意时效性*/public functionaddData(){$data=array();$data['access_token'] ='24xxxxxxxxxxxxxxxxxxxxae0';$data['expires_in'] ='24xxxxxxxxxxxxxxxxxxxxxxxxe0';$data['refresh_token'] ='edxxxxxxxxxxxxxxxxxxxxxxxxxxx0f';$data['time'] ='14xxxxx87475';$model=newJosModel();$res=$model->addData($data);echo$res;}/*** 查询京东快递物流跟踪信息*/public functiongetTrace(){//获取订单号//$waybillCode = $_POST['waybillCode'];//事例京东订单号$waybillCode="23457562180";//https://api.jd.com/routerjson 注:以后统一都使用https方式调用,之前使用http方式的请尽快切换一下入口地址。Vendor('Jos.jd.request.EtmsTraceGetRequest');$this->jd_client->appKey=$this->app_key;$this->jd_client->appSecret=$this->app_secret;$this->jd_client->accessToken=$this->access_token;$this->jd_client->serverUrl=$this->server_url;//SERVER_URL;$req=new\EtmsTraceGetRequest();$req->setWaybillCode($waybillCode);$resp=$this->jd_client->execute($req,$this->jd_client->accessToken);var_dump($resp);}/*** 360buy.order.get 获取单个订单*/public functiongetSingleOrder(){Vendor('Jos.jd.request.OrderGetRequest');$this->jd_client->appKey=$this->app_key;$this->jd_client->appSecret=$this->app_secret;$this->jd_client->accessToken=$this->access_token;$this->jd_client->serverUrl=$this->server_url;$req=new\OrderGetRequest();//事例京东订单号$waybillCode="23457562180";$req->setOrderId($waybillCode);//$req->setOptionalFields( "jingdong" );//$req->setOrderState( "jingdong" );$resp=$this->jd_client->execute($req,$this->jd_client->accessToken);var_dump($resp);}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值