微信公众号--开始开发

一、开始开发

1.接入

(1)填写服务器配置

(2)验证服务器地址的有效性

<?php

namespace app\index\controller;

class Index
{
    public function index()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = 'wx_token';
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            return $_GET["echostr"];
        }else{
            return false;
        }
    }
}

(3)依据接口文档实现业务逻辑

2.获取Access token

public function get_access_token($appid,$secret){
    $token_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret;
    $token = file_get_contents($token_url);
    return $token;
}
public function cacha_token(){
    $appid = '123456test';
    $secret = 'test1234567891011';
    $token = json_decode($this->get_access_token($appid,$secret));
    $expires_in = $token->expires_in;
    cache('app_access_token',$token->access_token,$expires_in-60);
}

返回说明

正常情况下,微信会返回下述JSON数据包给公众号:

{"access_token":"ACCESS_TOKEN","expires_in":7200}

参数说明

参数说明
access_token获取到的凭证
expires_in凭证有效时间,单位:秒
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值