Home Backend Development PHP Tutorial 微信公众平台开发之配置与请求_PHP

微信公众平台开发之配置与请求_PHP

May 30, 2016 am 08:46 AM
Micro-channel public platform

一、配置参数

define('WEIXIN_APPID', 'wxzzzzzzzz');
define('WEIXIN_APPSECRET', 'ouewjdsaudsamkh');
define('WEIXIN_TOKEN', '9973833232232');
define('WEIXIN_NOTIFY_URL', 'http://xx.com/xx/xx');
define('WEIXIN_MCHID', '322221121');
define('WEIXIN_KEY', 'xddsdswewew');
Copy after login

1)微信公众号开发中ID

WEIXIN_APPID: 应用ID

WEIXIN_APPSECRET: 应用密钥

进入到公众平台首页,点击开发者中心,赫然就能看到,配置页面中的,这两个默认就是有的。

2)服务器配置

WEIXIN_TOKEN,也就是token令牌,自定义的,必须为英文或数字,长度为3-32字符。

URL服务器地址,也就说微信公众号的入口地址。在这个页面中,我将做 签名验证 或接收事件消息, 点击查看微信相关文档 。

1、签名验证: 当做修改配置的时候,是需要通过这个地址做签名验证的

2、接收事件消息: 是指当关注的时候推送一些消息过来,以及可以做一些特定的逻辑操作

3)微信支付配置

点击微信支付菜单

WEIXIN_MCHID: 商户号,在商户信息中可以查看到

WEIXIN_NOTIFY_URL: 微信支付异步回调API,可以做更新订单状态,发推送等逻辑

WEIXIN_KEY: 设置这个支付密钥得登录微信支付商户平台,登录后点击进入API安全,然后下载证书和自己设置密钥,就OK了。

二、请求与调试

php中有个很方便的 curl ,这里提下CURLOPT_SSL_VERIFYPEER。一开始没加这个属性,请求微信服务器的时候每次返回数据是false。后面用firefox的HttpRequester模拟请求了一下,可以返回到数据,查找资料后发现要设置下这个属性。

CURLOPT_SSL_VERIFYPEER:是否检测服务器的证书是否由正规浏览器认证过的授权CA颁发的
/**
 * 原始POST
 * @param $url 请求的url地址
 * @param $raw 原始数据,可以为字符串或数组
 * @return mixed 返回请求值
 */
public function rawpost($url, $raw)
{
  $resource = curl_init();
  curl_setopt($resource, CURLOPT_POST, true);
  curl_setopt($resource, CURLOPT_URL, $url);
  curl_setopt($resource, CURLOPT_POSTFIELDS, $raw);
  curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($resource, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, false);
  //curl_setopt($resource, CURLOPT_HTTPHEADER, array('Expect:'));
  $data = curl_exec($resource);
  curl_close($resource);
  return $data;
}

这里推荐下HttpRequester,这个插件,可以模拟post、get等各种提交,content type也可以选择。

微信开发也提供了在线测试接口的地方。 点击查看微信公众平台接口调试工具 。

在请求调试的时候,微信会返回各种返回码。 点击查看全局返回码说明 。

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks 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)

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? What exactly is the non-blocking feature of ReactPHP? How to handle its blocking I/O operations? Apr 01, 2025 pm 03:09 PM

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...

See all articles