### Install Dependencies and Start Development Server with pnpm Source: https://github.com/w7corp/easywechat/blob/6.x/docs/README.md This snippet shows the commands to install project dependencies and start the local development server for the easywechat.com site. It requires pnpm to be installed and configured as the package manager. ```bash pnpm i pnpm run dev ``` -------------------------------- ### PHP: Full EasyWeChat Configuration Example Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/official-account/configuration.md Provides a comprehensive example of the configuration array for EasyWeChat, covering account details, response types, logging, HTTP client settings, and OAuth parameters. This example is useful for understanding all available options. ```php 'your-app-id', // AppID 'secret' => 'your-app-secret', // AppSecret 'token' => 'your-token', // Token 'aes_key' => '', // EncodingAESKey,兼容与安全模式下请一定要填写!!! /** *指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例 */ 'response_type' => 'array', /** * 日志配置 * * level: 日志级别, 可选为: * debug/info/notice/warning/error/critical/alert/emergency * path:日志文件位置(绝对路径!!!),要求可写权限 */ 'log' => [ 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod 'channels' => [ // 测试环境 'dev' => [ 'driver' => 'single', 'path' => '/tmp/easywechat.log', 'level' => 'debug', ], // 生产环境 'prod' => [ 'driver' => 'daily', 'path' => '/tmp/easywechat.log', 'level' => 'info', ], ], ], /** * 接口请求相关配置,超时时间等,具体可用参数请参考: * http://docs.guzzlephp.org/en/stable/request-config.html * * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。 * - retry_delay: 重试延迟间隔(单位:ms),默认 500 * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php */ 'http' => [ 'max_retries' => 1, 'retry_delay' => 500, 'timeout' => 5.0, // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri ], /** * OAuth 配置 * * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login * callback:OAuth授权完成后的回调页地址 */ 'oauth' => [ 'scopes' => ['snsapi_userinfo'], 'callback' => '/examples/oauth_callback.php', ], ]; ``` -------------------------------- ### Basic Official Account Server Example in PHP Source: https://github.com/w7corp/easywechat/blob/6.x/README.md This PHP code demonstrates the basic setup for an Official Account server using EasyWeChat. It initializes the application with configuration and sets up a simple response for incoming messages. Dependencies include the EasyWeChat library. ```php 'wx3cf0f39249eb0exxx', 'secret' => 'f1c242f4f28f735d4687abb469072xxx', 'aes_key' => 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG', 'token' => 'easywechat', ]; $app = new Application($config); $server = $app->getServer(); $server->with(fn() => "您好!EasyWeChat!"); $response = $server->serve(); ``` -------------------------------- ### Full Official Account Configuration Example in PHP Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/official-account/configuration.md This provides a comprehensive example of an EasyWeChat configuration array for an official account. It includes detailed settings for account information, response types, logging, HTTP client options, and OAuth scopes. This is suitable for production environments requiring extensive customization. ```php 'your-app-id', // AppID 'secret' => 'your-app-secret', // AppSecret 'token' => 'your-token', // Token 'aes_key' => '', // EncodingAESKey,兼容与安全模式下请一定要填写!!! /** * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例 */ 'response_type' => 'array', /** * 日志配置 * * level: 日志级别, 可选为: * debug/info/notice/warning/error/critical/alert/emergency * path:日志文件位置(绝对路径!!!),要求可写权限 */ 'log' => [ 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod 'channels' => [ // 测试环境 'dev' => [ 'driver' => 'single', 'path' => '/tmp/easywechat.log', 'level' => 'debug', ], // 生产环境 'prod' => [ 'driver' => 'daily', 'path' => '/tmp/easywechat.log', 'level' => 'info', ], ], ], /** * 接口请求相关配置,超时时间等,具体可用参数请参考: * http://docs.guzzlephp.org/en/stable/request-config.html * * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。 * - retry_delay: 重试延迟间隔(单位:ms),默认 500 * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php */ 'http' => [ 'max_retries' => 1, 'retry_delay' => 500, 'timeout' => 5.0, // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri ], /** * OAuth 配置 * * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login * callback:OAuth授权完成后的回调页地址 */ 'oauth' => [ 'scopes' => ['snsapi_userinfo'], 'callback' => '/examples/oauth_callback.php', ], ]; ``` -------------------------------- ### Install EasyWeChat with Composer Source: https://github.com/w7corp/easywechat/blob/6.x/README.md This command installs the EasyWeChat SDK using Composer. Ensure you have Composer installed and meet the PHP version requirements. ```bash composer require w7corp/easywechat ``` -------------------------------- ### Install EasyWeChat using Composer Source: https://github.com/w7corp/easywechat/wiki/installation Installs the EasyWeChat package using Composer, the dependency manager for PHP. This is the recommended installation method. ```shell composer require overtrue/wechat ``` -------------------------------- ### Full Example: Server Validation and Middleware Response in PHP Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/6.x/official-account/server.md A comprehensive example demonstrating the integration of server validation, event listener for subscription, and serving a response. This showcases a common workflow for setting up an official account server. ```php use EasyWeChat\OfficialAccount\Application; $config = [...]; $app = new Application($config); $server = $app->getServer(); $server->addEventListener('subscribe', function($message, \Closure $next) { return 'Thank you for following EasyWeChat!'; }); $response = $server->serve(); return $response; ``` -------------------------------- ### Complete OCR Example in PHP Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/mini-program/ocr.md A comprehensive example showcasing the initialization of the EasyWeChat mini-program and its OCR service, followed by examples of recognizing an ID card and a bank card. It also includes basic error checking and outputting extracted information. ```php use EasyWeChat\Factory; $config = [ 'app_id' => 'your-app-id', 'secret' => 'your-app-secret', // ... ]; $app = Factory::miniProgram($config); $ocr = $app->ocr; // 识别身份证正面 $result = $ocr->idcard('media_id_123', 'photo'); if ($result['errcode'] === 0) { $name = $result['name']; $idNumber = $result['id']; $address = $result['addr']; echo "姓名:{$name}\n"; echo "身份证号:{$idNumber}\n"; echo "地址:{$address}\n"; } // 识别银行卡 $result = $ocr->bankcard('media_id_456'); if ($result['errcode'] === 0) { $cardNumber = $result['number']; echo "银行卡号:{$cardNumber}\n"; } ``` -------------------------------- ### Handle Official Account Callbacks and Operations Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/open-platform/authorizer-delegate.md This example demonstrates how to set up a callback route for an Official Account managed through the Open Platform. It shows how to get the authorized account's server instance and configure message handling. It also provides an example of calling common API methods like fetching user lists or obtaining mini program session keys. ```php // Example callback handler for an Official Account Route::post('{appId}/callback', function ($appId) { // ... $officialAccount = $openPlatform->officialAccount($appId); $server = $officialAccount->server; // Note: This is the authorized account's server $server->push(function () { return 'Welcome!'; }); return $server->serve(); }); // Example of calling authorized account business logic Route::get('how-to-use', function () { // Get Official Account instance and fetch user list $officialAccount = $openPlatform->officialAccount('Authorized_Official_Account_APPID', 'Refresh-token'); $officialAccount->user->list(); // Get Mini Program instance and get session $miniProgram = $openPlatform->miniProgram('Authorized_Mini_Program_APPID', 'Refresh-token'); $miniProgram->auth->session('js-code'); // Other operations follow the same pattern }); ``` -------------------------------- ### Complete EasyWeChat Configuration Array Example Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/configuration.md Provides a comprehensive example of the configuration array structure for EasyWeChat. It includes settings for debug mode, basic account information (AppID, secret, token, AES key), logging, OAuth, payment, and Guzzle client. ```php true, /** * 账号基本信息,请从微信公众平台/开放平台获取 */ 'app_id' => 'your-app-id', // AppID 'secret' => 'your-app-secret', // AppSecret 'token' => 'your-token', // Token 'aes_key' => '', // EncodingAESKey,安全模式与兼容模式下请一定要填写!!! /** * 日志配置 * * level: 日志级别, 可选为: * debug/info/notice/warning/error/critical/alert/emergency     * permission:日志文件权限(可选),默认为null(若为null值,monolog会取0644)     * file:日志文件位置(绝对路径!!!),要求可写权限 */ 'log' => [ 'level' => 'debug', 'permission' => 0777, 'file' => '/tmp/easywechat.log', ], /** * OAuth 配置 * * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login * callback:OAuth授权完成后的回调页地址 */ 'oauth' => [ 'scopes' => ['snsapi_userinfo'], 'callback' => '/examples/oauth_callback.php', ], /** * 微信支付 */ 'payment' => [ 'merchant_id' => 'your-mch-id', 'key' => 'key-for-signature', 'cert_path' => 'path/to/your/cert.pem', // XXX: 绝对路径!!!! 'key_path' => 'path/to/your/key', // XXX: 绝对路径!!!! // 'device_info' => '013467007045764', // 'sub_app_id' => '', // 'sub_merchant_id' => '', // ... ], /** * Guzzle 全局设置 * * 更多请参考: http://docs.guzzlephp.org/en/latest/request-options.html */ 'guzzle' => [ 'timeout' => 3.0, // 超时时间(秒) //'verify' => false, // 关掉 SSL 认证(强烈不建议!!!) ], ]; ``` -------------------------------- ### Get EasyWeChat Application Instance Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/user.md This snippet shows how to initialize the EasyWeChat application and get the user service instance. It requires the Application class and an options array for configuration. ```php user; ``` -------------------------------- ### Example: Sending a Complete Template Message Source: https://github.com/w7corp/easywechat/wiki/template_message_service A comprehensive example of sending a template message using chained methods. It includes setting the template ID, user ID, URL, color, and the message data. ```php $userId = 'OPENID'; $templateId = 'ngqIpbwh8bUfcSsECmogfXcV14J0tQlEpBO27izEYtY'; $url = 'http://overtrue.me'; $color = '#FF0000'; $data = array( "first" => "CHECKOUTED", "keynote1" => "Chocolates", "keynote2" => "39.8 RMB", "keynote3" => "2014/9/16", "remark" => "Have a nice day!", ); $messageId = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send(); ``` -------------------------------- ### Usage Scenarios Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/mini-program/search.md Examples demonstrating how to use the submitPage API for various types of mini-programs. ```APIDOC ## Usage Scenarios ### E-commerce Mini-Program Product Page Submission This example shows how to submit product detail pages for an e-commerce mini-program, handling potential batching limits. ```php use EasyWeChat\Factory; $config = [ 'app_id' => 'your-app-id', 'secret' => 'your-app-secret', // ... ]; $app = Factory::miniProgram($config); $search = $app->search; // Batch submit product pages function submitProductPages($search, $products) { $pages = []; foreach ($products as $product) { $pages[] = [ 'path' => 'pages/product/detail', 'query' => http_build_query([ 'id' => $product['id'], 'category' => $product['category'], 'brand' => $product['brand'] ]) ]; } // WeChat recommends submitting no more than 1000 pages at a time $chunks = array_chunk($pages, 1000); foreach ($chunks as $chunk) { $result = $search->submitPage($chunk); if ($result['errcode'] === 0) { echo "Successfully submitted " . count($chunk) . " product pages\n"; } else { echo "Submission failed: {$result['errmsg']}\n"; } // Avoid rate limiting sleep(1); } } // Example product data $products = [ [ 'id' => 'prod_001', 'category' => 'electronics', 'brand' => 'apple' ], [ 'id' => 'prod_002', 'category' => 'clothing', 'brand' => 'nike' ], [ 'id' => 'prod_003', 'category' => 'books', 'brand' => 'penguin' ] ]; submitProductPages($search, $products); ``` ### Content Platform Page Submission This example demonstrates submitting various content pages, including articles, videos, and user profiles. ```php // Submit article and video pages function submitContentPages($search) { // Article pages $articlePages = [ [ 'path' => 'pages/article/detail', 'query' => 'id=1001&category=technology' ], [ 'path' => 'pages/article/detail', 'query' => 'id=1002&category=lifestyle' ] ]; // Video pages $videoPages = [ [ 'path' => 'pages/video/player', 'query' => 'vid=v001&playlist=tech' ], [ 'path' => 'pages/video/player', 'query' => 'vid=v002&playlist=entertainment' ] ]; // User pages $userPages = [ [ 'path' => 'pages/user/profile', 'query' => 'uid=user001' ], [ 'path' => 'pages/user/profile', 'query' => 'uid=user002' ] ]; // Merge all pages $allPages = array_merge($articlePages, $videoPages, $userPages); $result = $search->submitPage($allPages); if ($result['errcode'] === 0) { echo "Content pages submitted successfully, a total of " . count($allPages) . " pages submitted\n"; } else { echo "Submission failed: {$result['errmsg']}\n"; } } submitContentPages($search); ``` ### Service-Oriented Mini-Program Page Submission Example for submitting pages of a restaurant booking mini-program. ```php // Restaurant booking mini-program function submitRestaurantPages($search) { $pages = [ // Restaurant detail pages [ 'path' => 'pages/restaurant/detail', 'query' => 'restaurant_id=rest001&city=beijing' ], [ 'path' => 'pages/restaurant/detail', 'query' => 'restaurant_id=rest002&city=shanghai' ], // Dish pages [ 'path' => 'pages/menu/dish', 'query' => 'dish_id=dish001&restaurant_id=rest001' ], // Booking pages [ 'path' => 'pages/booking/form', 'query' => 'restaurant_id=rest001&date=2023-12-01' ], // Promotion pages [ 'path' => 'pages/promotion/detail', 'query' => 'promo_id=promo001&type=discount' ] ]; $result = $search->submitPage($pages); if ($result['errcode'] === 0) { echo "Restaurant pages submitted successfully\n"; } } submitRestaurantPages($search); ``` ``` -------------------------------- ### Clone Documentation Repository Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/contributing.md This command clones the EasyWeChat documentation repository to your local machine. It allows you to edit and update the project's documentation. ```shell $ git clone https://github.com//site.git $ cd docs ``` -------------------------------- ### Get JSSDK Instance (PHP) Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/js.md This snippet shows how to initialize the EasyWeChat Application and retrieve the JSSDK instance. It requires the 'EasyWeChat\Foundation\Application' class and an options array for configuration. ```php js; ?> ``` -------------------------------- ### Include Autoloader in PHP Project Source: https://github.com/w7corp/easywechat/wiki/installation Includes the autoload.php file from the downloaded EasyWeChat package to enable class loading. This is an alternative installation method for projects not using Composer. ```php oa->approvalRecords(1492617600, 1492790400, '201704240001'); $app->oa->approvalRecords(1492617600, 1492790400); ``` -------------------------------- ### WeDrive Initialization Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/wework/wedrive.md Obtain an instance of the WeDrive service. ```APIDOC ## WeDrive Initialization ### Description Obtain an instance of the WeDrive service. ### Method Not Applicable (Initialization) ### Endpoint Not Applicable (Initialization) ### Request Example ```php $wedrive = $app->wedrive; ``` ### Response Example (Instance of WeDrive service) ``` -------------------------------- ### Data Statistics - Get Member Behavior Data (PHP) Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/wework/external-contact.md Retrieves behavioral data for specified employees within a given time range. Requires a list of user IDs and a start and end timestamp. ```php $userIds = [ 'zhangsan', 'lisi' ]; $from = 1536508800; $to = 1536940800; $app->external_contact_statistics->userBehavior($userIds, $from, $to); ``` -------------------------------- ### Get Public Template Titles by Category - PHP Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/mini-program/subscribe_message.md Retrieves a list of public template titles based on provided category IDs. Supports pagination with start and limit parameters for efficient data retrieval. ```php $ids = [612, 613]; // 类目 id $start = 0; // 用于分页,表示从 start 开始。从 0 开始计数。 $limit = 30; // 用于分页,表示拉取 limit 条记录。最大为 30。 $app->subscribe_message->getTemplateTitles($ids, $start, $limit); ``` -------------------------------- ### EasyWeChat OA - Get Monthly Check-in Report Data (PHP) Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/wework/oa.md Retrieves monthly summary data for employee check-ins within a given period. Requires start and end timestamps and a list of user IDs. ```php $app->oa->checkinMonthData(int $startTime, int $endTime, array $userids); ``` -------------------------------- ### Initialize EasyWeChat Application and Get Notice Instance Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/notice.md This snippet shows how to instantiate the EasyWeChat application with configuration options and then retrieve the 'notice' instance, which is used for sending template messages. It requires the `EasyWeChatFoundationApplication` namespace. ```php notice; ``` -------------------------------- ### Initialize WeChat Official Account Application (PHP) Source: https://context7.com/w7corp/easywechat/llms.txt Demonstrates how to initialize and configure the EasyWeChat Official Account application. This includes setting up basic credentials, token, encryption keys, and optional HTTP configurations. It shows how to access core services like the server, client, OAuth, and utilities, and provides an example of making an API call. ```php 'wx3cf0f39249eb0e123', 'secret' => 'f1c242f4f28f735d4687abb469072abc', 'token' => 'your_token', // For message signature verification 'aes_key' => 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG', // For message encryption // Optional configurations 'use_stable_access_token' => false, 'http' => [ 'timeout' => 5.0, 'retry' => true, 'max_retries' => 2, 'throw' => true, // Throw exceptions on API errors ], 'oauth' => [ 'scopes' => ['snsapi_userinfo'], 'redirect_url' => 'https://example.com/callback', ], ]; $app = new Application($config); // Access core services $server = $app->getServer(); // Message/callback server $client = $app->getClient(); // HTTP client with auto token refresh $oauth = $app->getOAuth(); // OAuth authentication $utils = $app->getUtils(); // JS-SDK utilities $accessToken = $app->getAccessToken()->getToken(); // Manual token access // Make API calls $response = $client->get('/cgi-bin/user/info', [ 'query' => ['openid' => 'o6_bmjrPTlm6_2sgVt7hMZOPfoobar'], ]); $userInfo = $response->toArray(); ``` -------------------------------- ### EasyWeChat OA - Get Daily Check-in Report Data (PHP) Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/wework/oa.md Retrieves daily summary data for employee check-ins within a given period. Requires start and end timestamps and a list of user IDs. ```php $app->oa->checkinDayData(int $startTime, int $endTime, array $userids); ``` -------------------------------- ### Create Store Mini Program (PHP) Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/official-account/store.md Submits information to create a new store mini program. Requires administrator confirmation and has a 24-hour timeout for confirmation. Supports various base information fields and media uploads for qualifications and head images. ```php $app->store->createMerchant($baseInfo); ``` ```php unset($app); $info = [ "first_catid" => 476, //categories 接口获取的一级类目id "second_catid" => 477, //categories 接口获取的二级类目id "qualification_list" => "RTZgKZ386yFn5kQSWLTxe4bqxwgzGBjs3OE02cg9CVQk1wRVE3c8fjUFX7jvpi-P", "headimg_mediaid" => "RTZgKZ386yFn5kQSWLTxe4bqxwgzGBjs3OE02cg9CVQk1wRVE3c8fjUFX7jvpi-P", "nickname" => "hardenzhang308", "intro" => "hardenzhangtest", "org_code" => "", "other_files" => "" ]; $result = $app->store->createMerchant($info); ``` -------------------------------- ### Implement Custom Cache Driver Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/cache.md This example shows how to create a custom cache driver for EasyWeChat by implementing the DoctrineCommonCacheCache interface. The interface requires methods for fetching, checking existence, saving, deleting, and getting statistics of cache entries. The custom driver can then be integrated into the EasyWeChat configuration. ```php $myCacheDriver, ]; $wechatApp = new Application($options); ``` -------------------------------- ### Initialize EasyWeChat Application with Options Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/configuration.md Demonstrates how to create an instance of the EasyWeChat Application using an options array. It also shows how to dynamically update configuration values after instantiation, such as modifying the OAuth callback URL. ```php use EasyWeChat\Foundation\Application; $options = [ // ... ]; $app = new Application($options); /** * 如果想要在Application实例化完成之后, 修改某一个options的值, * 比如服务商+子商户支付回调场景, 所有子商户订单支付信息都是通过同一个服务商的$option 配置进来的, * 当oauth在微信端验证完成之后, 可以通过动态设置merchant_id来区分具体是哪个子商户 */ $app['config']->set('oauth.callback','wechat/oauthcallback/'. $sub_merchant_id->id); ``` -------------------------------- ### Implement Custom PSR-16 Cache Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/customize/cache.md This example defines a custom cache class that implements the PSR-16 Simple Cache interface. It provides placeholder methods for basic cache operations like get, set, delete, clear, and their multiple-key counterparts. This allows for flexible cache backend implementations. ```php rebind('cache', new MyCustomCache()); ``` -------------------------------- ### Get User Summary Data - PHP Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/official-account/data_cube.md This PHP snippet demonstrates how to retrieve daily user summary data from the EasyWeChat library. It requires a starting and ending date as input and returns an array of user statistics, including new users and cancellations. Data prior to December 1, 2014, is not available. ```php $userSummary = $app->data_cube->userSummary('2014-12-07', '2014-12-08'); var_dump($userSummary); // //[ // { // "ref_date": "2014-12-07", // "user_source": 0, // "new_user": 0, // "cancel_user": 0 // } // //后续还有ref_date在begin_date和end_date之间的数据 // ] ``` -------------------------------- ### Create Store Mini Program - PHP Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/official-account/store.md Creates a new store mini program. Requires administrator confirmation after submission. The `$baseInfo` parameter includes essential details like category IDs, qualification documents (media IDs), store nickname, and introduction. Media IDs are obtained using the 'media/upload' interface. ```php $app->store->createMerchant($baseInfo); ``` ```php $info = [ "first_catid" => 476, //categories 接口获取的一级类目id "second_catid" => 477, //categories 接口获取的二级类目id "qualification_list" => "RTZgKZ386yFn5kQSWLTxe4bqxwgzGBjs3OE02cg9CVQk1wRVE3c8fjUFX7jvpi-P", "headimg_mediaid" => "RTZgKZ386yFn5kQSWLTxe4bqxwgzGBjs3OE02cg9CVQk1wRVE3c8fjUFX7jvpi-P", "nickname" => "hardenzhang308", "intro" => "hardenzhangtest", "org_code" => "", "other_files" => "" ]; $result = $app->store->createMerchant($info); ``` -------------------------------- ### Implement Custom PSR-16 Cache Interface Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/customize/cache.md This example provides a template for creating a custom cache class in PHP that adheres to the PSR-16 Simple Cache interface. It includes placeholder methods for standard cache operations like get, set, delete, clear, and their multiple-key counterparts. This allows for integration of unique caching logic into EasyWeChat. ```php store->createFromMap($baseInfo);" } ``` ### Request Body Example ```json { "example": "{\n \"name\": \"hardenzhang\",\n \"longitude\": \"113.323753357\",\n \"latitude\": \"23.0974903107\",\n \"province\": \"广东省\",\n \"city\": \"广州市\",\n \"district\": \"海珠区\",\n \"address\": \"TIT\",\n \"category\": \"类目1:类目2\",\n \"telephone\": \"12345678901\",\n \"photo\": \"http://mmbiz.qpic.cn/mmbiz_png/tW66AWE2K6ECFPcyAcIZTG8RlcR0sAqBibOm8gao5xOoLfIic9ZJ6MADAktGPxZI7MZLcadZUT36b14NJ2cHRHA/0?wx_fmt=png\",\n \"license\": \"http://mmbiz.qpic.cn/mmbiz_png/tW66AWE2K6ECFPcyAcIZTG8RlcR0sAqBibOm8gao5xOoLfIic9ZJ6MADAktGPxZI7MZLcadZUT36b14NJ2cHRHA/0?wx_fmt=png\",\n \"introduct\": \"test\",\n \"districtid\": \"440105\"\n}" } ``` ### Response #### Success Response (200) - **result** (object) - The result of the store creation on Tencent Maps. #### Response Example ```json { "example": "[...creation result]" } ``` **Note:** The review result for creating a store on Tencent Maps will be pushed as an event. The review period is 3 business days. If no event is pushed immediately after submission, it is under review. ``` -------------------------------- ### Instantiate Open Platform Application Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/open_platform.md This section shows how to initialize the EasyWeChat application with Open Platform configuration options. ```APIDOC ## Instantiate Open Platform Application ### Description Initialize the EasyWeChat application with the necessary Open Platform credentials. ### Method Instantiation ### Endpoint N/A ### Parameters #### Request Body - **options** (array) - Required - Configuration options including `open_platform` details. - **open_platform** (array) - Required - Open Platform specific configuration. - **app_id** (string) - Required - Your component app ID. - **secret** (string) - Required - Your component secret. - **token** (string) - Required - Your component token. - **aes_key** (string) - Required - Your component AES key. ### Request Example ```php [ 'app_id' => 'component-app-id', 'secret' => 'component-secret', 'token' => 'component-token', 'aes_key' => 'component-aes-key' ], // ... ]; $app = new Application($options); $openPlatform = $app->open_platform; ``` ### Response #### Success Response (Object) - **openPlatform** (object) - An instance of the Open Platform application. ``` -------------------------------- ### Configure EasyWeChat Work Application Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/6.x/work/utils.md Initializes the EasyWeChat Work application with provided configuration and retrieves the utility instance. This is the first step before using any utility methods. It requires a configuration array to be passed to the `Application` constructor. ```php getUtils(); ``` -------------------------------- ### Configure Redis Cache with RedisCache in Symfony 3.4+ Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/4.x/customize/cache.md This code example shows how to integrate Redis caching in Symfony 3.4 and later versions using the RedisCache class. It assumes the phpredis extension is installed. The process involves connecting to a Redis instance and then creating a RedisCache object, which is subsequently used to replace the application's default cache service. ```php use Symfony\Component\Cache\Simple\RedisCache; // 创建 redis 实例 $redis = new Redis(); $redis->connect('redis_host', 6379); // 创建缓存实例 $cache = new RedisCache($redis); // 替换应用中的缓存 $app->rebind('cache', $cache); ``` -------------------------------- ### Get EasyWeChat Application Instance Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/material.md Initializes the EasyWeChat application with provided options to access various services, including material management. This is a prerequisite for all subsequent API calls. ```php material; // Temporary material instance $temporary = $app->material_temporary; ``` -------------------------------- ### Poi API - Get Instance Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/3.x/poi.md This section explains how to get an instance of the Poi service from the EasyWeChat application. ```APIDOC ## Poi API - Get Instance ### Description This endpoint provides access to the Poi service, which is used for managing store information. ### Method N/A (Instantiates a service object) ### Endpoint N/A ### Parameters None ### Request Example ```php poi; ``` ### Response N/A (Returns a Poi service object) ``` -------------------------------- ### Create Store API Source: https://github.com/w7corp/easywechat/blob/6.x/docs/src/5.x/official-account/store.md Creates a new store with provided basic information and qualifications. Requires administrator confirmation. ```APIDOC ## POST /store/createMerchant ### Description Creates a new store. The submission requires confirmation from the official account administrator. If the primary administrator does not confirm within 24 hours, the submission can be retried. ### Method POST ### Endpoint /store/createMerchant ### Parameters #### Request Body - **baseInfo** (object) - Required - An object containing the basic information for the store. - **first_catid** (integer) - Required - The ID of the first-level category obtained from the `categories` interface. - **second_catid** (integer) - Required - The ID of the second-level category obtained from the `categories` interface. - **qualification_list** (string) - Required - Temporary media ID (`mediaid`) for category-related documents. If `sensitive_type` for the `second_catid` is 1, this field can contain 0 to 5 `mediaid`s. - **headimg_mediaid** (string) - Required - Temporary media ID (`mediaid`) for the store's avatar. `mediaid`s are obtained using the `media/upload` interface. - **nickname** (string) - Required - The nickname of the store. - **intro** (string) - Required - A brief introduction to the store. - **org_code** (string) - Optional - Organization code. - **other_files** (string) - Optional - Other relevant files. ### Request Example ```json { "example": "{\"first_catid\": 476, \"second_catid\": 477, \"qualification_list\": \"RTZgKZ386yFn5kQSWLTxe4bqxwgzGBjs3OE02cg9CVQk1wRVE3c8fjUFX7jvpi-P\", \"headimg_mediaid\": \"RTZgKZ386yFn5kQSWLTxe4bqxwgzGBjs3OE02cg9CVQk1wRVE3c8fjUFX7jvpi-P\", \"nickname\": \"hardenzhang308\", \"intro\": \"hardenzhangtest\", \"org_code\": \"\", \"other_files\": \"\"}" } ``` ### Response #### Success Response (200) - **result** (object) - Indicates the result of the store creation request. #### Response Example ```json { "example": "{\"errcode\": 0, \"errmsg\": \"ok\"}" } ``` **Note:** The review result for store creation will be pushed as an event to the callback URL provided by the merchant. ```