相思资源网 Design By www.200059.com

本文实例讲述了php版微信自动获取收货地址api用法。分享给大家供大家参考,具体如下:

微信公众平台现在是越来越强大了,我们可以通过各种api接口来与平台对接获取对应的数据了,下面来看一个由php实现的微信自动获取收货地址api程序,具体如下.

关于接口的说明我就不介绍了,在官方可以看到下面只看处理程序.

public function get_address_api() {
  $APPID=C('APPID');
  $SCRETID=C('SCRETID');
  if (!isset($_GET['code'])) {
    $backurl = $this->get_url();
    $url = "https://open.weixin.qq.com/connect/oauth2/authorize".$APPID."&redirect_uri=".urlencode($backurl)."&response_type=code&scope=jsapi_address&state=123#wechat_redirect";
    // snsapi_userinfo
    Header("Location: $url");
    exit;
  } else {
    $code = $_GET['code'];
    $url = "https://api.weixin.qq.com/sns/oauth2/access_token".$APPID."&secret=".$SCRETID."&code=".$code."&grant_type=authorization_code";
    $re = file_get_contents($url);
    $rearr = json_decode($re,true);
    $backurl = $this->get_url();
    $openid = $rearr['openid'];
    $unionid = $rearr['unionid'];
    $asstoken = $rearr['access_token'];
    S('jsapi_address_token'.$openid,$asstoken,7200);
    $data['appid']=$APPID;
    $data['url']=$backurl;
    $data['timestamp']=time();
    $data['timestamp']= (string)($data['timestamp']);
    $data['noncestr']=$this->getRandStr(10);
    $data['accesstoken']=$asstoken;
    foreach ($data as $k => $v) {
      $Parameters[$k] = $v;
    }
    //签名步骤一:按字典序排序参数
    ksort($Parameters);
    $String = $this->formatBizQueryParaMap($Parameters, false);
    $data['addrsign']=SHA1($String);
    $this->assign('data',$data);
  }
  $this->siteDisplay('address_api');
}

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP微信开发技巧汇总》、《PHP编码与转码操作技巧汇总》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

标签:
php,微信,自动获取,收货地址,api

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“php版微信自动获取收货地址api用法示例”

暂无php版微信自动获取收货地址api用法示例的评论...