Home Backend Development PHP Tutorial Usage analysis of thinkPHP WeChat sharing interface JSSDK

Usage analysis of thinkPHP WeChat sharing interface JSSDK

Jun 08, 2018 pm 02:50 PM
thinkphp WeChat

This article mainly introduces the usage of thinkPHP WeChat sharing interface JSSDK, and analyzes the specific steps and related operating techniques of thinkPHP calling WeChat sharing interface in the form of examples. Friends in need can refer to the following

The examples in this article describe thinkPHP WeChat sharing interface JSSDK usage. Share it with everyone for your reference, the details are as follows:

First add the access_token table in the database:

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for access_token
-- ----------------------------
DROP TABLE IF EXISTS `access_token`;
CREATE TABLE `access_token` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `access_token` char(64) NOT NULL COMMENT '令牌-唯一标识',
 `expires_time` varchar(64) DEFAULT NULL COMMENT '过期时间',
 `ticket` char(64) NOT NULL COMMENT '临时票据',
 `ticket_expires_time` varchar(64) DEFAULT NULL COMMENT '过期的票据时间',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='token缓存表';
Copy after login
/**
* 添加微信分享接口
* 第一步:access token
*/
public function getAccessToken(){
  $appid = '你的appid'; //获取用户唯一凭证
  $secret = '你的secret'; //用户唯一凭证密钥
  $time = time()+7000; //当前时间+2小时等于过期时间
  if (!$token) {
    $res = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' .$appid.'&secret='. $secret);
    $res = json_decode($res, true);
    $token = $res['access_token'];
    $model = D('access_token'); //把获取的token存储到数据库中
    if($token){
      $data = array(
      'access_token' => $token,
      'expires_time' => $time
      );
      $data = $model->add($data); //把获得的token存储到数据库中
    }
  }
  return $token;
}
Copy after login
/**
* 添加微信分享接口
* 第二步:用第一步拿到的access_token 采用http GET方式请求获得jsapi_ticket
*/
public function getJsapiTicket(){
  $time = time()+7000; //当前时间+2小时等于过期时间
  $map['ticket_expires_time'] = array('gt',time());
  $res = D('access_token')->where('ticket_expires_time')->field('ticket')->find();
  if($res){
    $ticket = $res['ticket'];
    $result['result'] = $ticket; //没查询到符合条件的
    jsonpReturn($result);
  } else{
    $token = $this->getAccessToken();
    $res = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$token."&type=jsapi");
    $res = json_decode($res, true);
    $ticket = $res['ticket'];
    // ticket不能频繁的访问接口来获取,在每次获取后,我们把它保存到数据库中。
    $model = D('access_token'); //把获取的ticket存储到数据库中
    if($ticket){
      $data = array(
      'access_token' => $token,
      'expires_time' => $time,
      'ticket' => $ticket,
      'ticket_expires_time' => $time
      );
      $data = $model->add($data); //把获得的token存储到数据库中
    }
    $result['result'] = $ticket; //没查询到符合条件的
    jsonpReturn($result);
  }
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's study, more related Please pay attention to the PHP Chinese website for content!

Related recommendations:

About the analysis of the callback problem of the thinkPHP framework docking with Alipay’s instant payment interface

About thinkphp3.2 Analysis of embedding Baidu editor ueditor

How to use thinkphp to obtain the client IP

The above is the detailed content of Usage analysis of thinkPHP WeChat sharing interface JSSDK. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek image generation tutorial deepseek image generation tutorial Feb 19, 2025 pm 04:15 PM

DeepSeek: A powerful AI image generation tool! DeepSeek itself is not an image generation tool, but its powerful core technology provides underlying support for many AI painting tools. Want to know how to use DeepSeek to generate images indirectly? Please continue reading! Generate images with DeepSeek-based AI tools: The following steps will guide you to use these tools: Launch the AI ​​Painting Tool: Search and open a DeepSeek-based AI Painting Tool (for example, search "Simple AI"). Select the drawing mode: select "AI Drawing" or similar function, and select the image type according to your needs, such as "Anime Avatar", "Landscape"

gateio Chinese official website gate.io trading platform website gateio Chinese official website gate.io trading platform website Feb 21, 2025 pm 03:06 PM

Gate.io, a leading cryptocurrency trading platform founded in 2013, provides Chinese users with a complete official Chinese website. The website provides a wide range of services, including spot trading, futures trading and lending, and provides special features such as Chinese interface, rich resources and community support.

List of handling fees for okx trading platform List of handling fees for okx trading platform Feb 15, 2025 pm 03:09 PM

The OKX trading platform offers a variety of rates, including transaction fees, withdrawal fees and financing fees. For spot transactions, transaction fees vary according to transaction volume and VIP level, and adopt the "market maker model", that is, the market charges a lower handling fee for each transaction. In addition, OKX also offers a variety of futures contracts, including currency standard contracts, USDT contracts and delivery contracts, and the fee structure of each contract is also different.

ThinkPHP6 routing: How to completely obtain URL parameters containing special characters such as Chinese? ThinkPHP6 routing: How to completely obtain URL parameters containing special characters such as Chinese? Apr 01, 2025 pm 02:51 PM

ThinkPHP6 routing parameters are processed in Chinese and complete acquisition. In the ThinkPHP6 framework, URL parameters containing special characters (such as Chinese and punctuation marks) are often processed...

How to solve the problem of cURL error 77 when connecting to Elasticsearch 8 using ThinkPHP6 and elasticsearch-php clients? How to solve the problem of cURL error 77 when connecting to Elasticsearch 8 using ThinkPHP6 and elasticsearch-php clients? Mar 31, 2025 pm 11:36 PM

Using the ThinkPHP6 framework combined with elasticsearch-php client to operate Elasticsearch...

gateio exchange app old version gateio exchange app old version download channel gateio exchange app old version gateio exchange app old version download channel Mar 04, 2025 pm 11:36 PM

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.

Ouyi Exchange app domestic download tutorial Ouyi Exchange app domestic download tutorial Mar 21, 2025 pm 05:42 PM

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Mar 04, 2025 pm 04:51 PM

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

See all articles