Top Related Projects
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
📦 一个 PHP 微信 SDK
可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了
可能是我用过的最优雅的 Alipay/WeChat/Unipay 的 laravel 支付扩展包了
Quick Overview
The w7corp/easywechat
project is a comprehensive and user-friendly SDK for building WeChat applications in PHP. It provides a set of APIs and tools to interact with various WeChat services, including official accounts, mini-programs, payment, and more.
Pros
- Comprehensive Functionality: The SDK covers a wide range of WeChat features, making it a one-stop solution for building WeChat-based applications.
- Ease of Use: The project has a well-designed and intuitive API, making it easy for developers to integrate WeChat functionality into their applications.
- Active Development: The project is actively maintained, with regular updates and bug fixes, ensuring compatibility with the latest WeChat platform changes.
- Extensive Documentation: The project comes with detailed documentation, including examples and guides, which helps developers get started quickly.
Cons
- Dependency on WeChat Platform: The SDK is tightly coupled with the WeChat platform, which means that any changes or updates to the WeChat API may require updates to the SDK.
- Limited Support for Non-PHP Environments: The SDK is primarily designed for PHP-based applications, and may not be as well-suited for projects in other programming languages.
- Potential Learning Curve: While the SDK is generally easy to use, developers who are new to WeChat development may still face a learning curve when getting started with the project.
- Limited Community Support: Compared to some other popular PHP libraries, the
w7corp/easywechat
project may have a smaller community of contributors and users, which could impact the availability of support and resources.
Code Examples
Here are a few examples of how to use the w7corp/easywechat
SDK:
- Sending a Text Message to a WeChat Official Account:
use EasyWeChat\Factory;
$config = [
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
// ... other configurations
];
$app = Factory::officialAccount($config);
$response = $app->customer_service->message('text')
->from('from-user-id')
->to('to-user-id')
->content('Hello, WeChat!')
->send();
- Handling a WeChat Mini-Program Event:
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
use EasyWeChat\Kernel\Contracts\MessageInterface;
class MyEventHandler implements EventHandlerInterface
{
public function handle(MessageInterface $message): MessageInterface
{
// Handle the event here
if ($message->getMsgType() === 'event') {
// Handle the event
if ($message->getEvent() === 'subscribe') {
// Handle the subscribe event
return $message->reply('Welcome to my mini-program!');
}
}
return $message;
}
}
$app = Factory::miniProgram($config);
$app->server->push(MyEventHandler::class);
$app->server->serve()->send();
- Initiating a WeChat Payment:
use EasyWeChat\Factory;
$config = [
'app_id' => 'your-app-id',
'mch_id' => 'your-mch-id',
'key' => 'your-api-key',
// ... other configurations
];
$app = Factory::payment($config);
$result = $app->order->unify([
'body' => 'Your Order',
'out_trade_no' => 'unique-order-no',
'total_fee' => 1, // 0.01 CNY
'notify_url' => 'https://example.com/payments/notify',
'trade_type' => 'JSAPI',
'openid' => 'user-open-id',
]);
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
$prepayId = $result->prepay_id;
// Generate the payment parameters and return them to the client
}
Competitor Comparisons
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
Pros of laravel/laravel
- Comprehensive and well-documented framework, providing a robust set of tools and features for building web applications.
- Large and active community, with a wealth of resources, packages, and third-party integrations available.
- Emphasis on convention over configuration, which can speed up development and promote consistency.
Cons of laravel/laravel
- Steeper learning curve compared to EasyWeChat, especially for developers new to the Laravel ecosystem.
- Larger codebase and more complex structure, which can make it more challenging to understand and customize for specific use cases.
- Potential performance overhead compared to a more lightweight solution like EasyWeChat.
Code Comparison
laravel/laravel (5 lines)
Route::get('/', function () {
return view('welcome');
});
Route::get('/dashboard', function () {
return view('dashboard');
});
w7corp/easywechat (5 lines)
$app = Factory::officialAccount([
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
'token' => 'your-token',
'aes_key' => 'your-aes-key',
]);
📦 一个 PHP 微信 SDK
Pros of EasyWeChat
- Comprehensive and well-documented functionality for interacting with the WeChat API
- Active community and regular updates to keep up with WeChat platform changes
- Supports a wide range of WeChat features, including payment, official accounts, and more
Cons of EasyWeChat
- Larger codebase and more complex setup compared to some other WeChat SDK options
- May have a steeper learning curve for developers new to the WeChat ecosystem
- Potential performance overhead for smaller or simpler WeChat integrations
Code Comparison
EasyWeChat:
$app = Factory::officialAccount([
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
// 'token' => 'your-token',
// 'aes_key' => 'your-aes-key',
]);
$response = $app->server->serve();
EasyWeChat (v2):
$app = new Application([
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
// 'token' => 'your-token',
// 'aes_key' => 'your-aes-key',
]);
$response = $app->server->serve();
The main difference is the use of the Factory
class in the original EasyWeChat library, compared to the direct Application
class instantiation in the v2 version.
可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了
Pros of yansongda/pay
- Supports a wider range of payment gateways, including Alipay, WeChat Pay, and UnionPay.
- Provides a more comprehensive set of features, such as refunds, transfers, and recurring payments.
- Offers better documentation and more active community support.
Cons of yansongda/pay
- May have a steeper learning curve for developers already familiar with EasyWeChat.
- Potentially less optimized for WeChat-specific use cases compared to EasyWeChat.
- May have a larger codebase and dependencies, which could impact performance in some scenarios.
Code Comparison
EasyWeChat:
$app = Factory::officialAccount([
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
'token' => 'your-token',
'aes_key' => 'your-aes-key',
]);
$response = $app->server->serve();
yansongda/pay:
$alipay = Pay::alipay([
'app_id' => 'your-app-id',
'notify_url' => 'http://example.com/notify',
'return_url' => 'http://example.com/return',
'ali_public_key' => 'path/to/ali_public_key.pem',
'private_key' => 'path/to/private_key.pem',
'log' => [
'file' => './logs/alipay.log',
'level' => 'debug',
'type' => 'single',
],
]);
可能是我用过的最优雅的 Alipay/WeChat/Unipay 的 laravel 支付扩展包了
Pros of Laravel Pay
- Comprehensive Payment Gateway Support: Laravel Pay supports a wide range of payment gateways, including Alipay, WeChat Pay, UnionPay, and more, making it a versatile solution for various payment needs.
- Intuitive API: The API provided by Laravel Pay is straightforward and easy to use, simplifying the integration process for developers.
- Laravel Integration: As a Laravel-specific package, Laravel Pay seamlessly integrates with the Laravel framework, allowing developers to leverage the ecosystem's features and best practices.
Cons of Laravel Pay
- Limited to Laravel: While the tight integration with Laravel is a strength, it also means that Laravel Pay is not suitable for non-Laravel projects, limiting its broader applicability.
- Fewer Contributors: Compared to EasyWeChat, Laravel Pay has a smaller community and fewer contributors, which may impact the pace of development and the availability of support.
- Narrower Scope: EasyWeChat covers a broader range of WeChat-related features, while Laravel Pay is primarily focused on payment processing, potentially limiting its usefulness for more complex WeChat integrations.
Code Comparison
EasyWeChat:
$app = Factory::officialAccount([
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
// 'token' => 'your-token',
// 'aes_key' => 'your-aes-key',
]);
$response = $app->server->serve();
Laravel Pay:
$alipay = Pay::alipay([
'app_id' => 'your-app-id',
'secret' => 'your-app-secret',
'key' => 'your-key',
'return_url' => 'https://example.com/alipay/return',
'notify_url' => 'https://example.com/alipay/notify',
]);
$alipay->web([
'out_trade_no' => time(),
'total_amount' => 1,
'subject' => 'Test Order',
])->send();
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
EasyWeChat
ð¦ ä¸ä¸ª PHP 微信å¼å SDKï¼å¼æº SaaS å¹³å°æä¾å å¾®æ æä¸å¼æºäº§åã
ç¯å¢éæ±
- PHP >= 8.0.2
- Composer >= 2.0
å®è£
composer require w7corp/easywechat
使ç¨ç¤ºä¾
åºæ¬ä½¿ç¨ï¼ä»¥å ¬ä¼å·æå¡ç«¯ä¸ºä¾ï¼:
<?php
use EasyWeChat\OfficialAccount\Application;
$config = [
'app_id' => 'wx3cf0f39249eb0exxx',
'secret' => 'f1c242f4f28f735d4687abb469072xxx',
'aes_key' => 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
'token' => 'easywechat',
];
$app = new Application($config);
$server = $app->getServer();
$server->with(fn() => "æ¨å¥½ï¼EasyWeChatï¼");
$response = $server->serve();
ææ¡£åé¾æ¥
å®ç½ · 讨论 · æ´æ°çç¥
:heart: æ¯ææ
å¦æä½ å欢æç项ç®å¹¶æ³æ¯æå®ï¼ç¹å»è¿é :heart:
ç± JetBrains èµå©
é常æè°¢ Jetbrains 为ææä¾ç IDE å¼æºè®¸å¯ï¼è®©æå®ææ¤é¡¹ç®åå ¶ä»å¼æºé¡¹ç®ä¸çå¼åå·¥ä½ã
å¯ç±çè´¡ç®è 们
License
MIT
Top Related Projects
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
📦 一个 PHP 微信 SDK
可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了
可能是我用过的最优雅的 Alipay/WeChat/Unipay 的 laravel 支付扩展包了
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot