ÔõÑùÔÚThinkPHP6ÖÐʹÓÃ΢ÐÅSDK£¿
Ëæ×Å΢ÐŵÄÊ¢ÐУ¬Ô½À´Ô½¶àµÄ¿ª·¢ÕßÐèÒªÔÚËûÃǵÄÓ¦ÓóÌÐòÖм¯³É΢ÐÅsdk¡£¶øÔÚthinkphp6ÖУ¬ÎÒÃÇ¿ÉÒÔºÜÈÝÒ×µØʵÏÖÕâһĿµÄ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃ΢ÐÅsdk¾ÙÐпª·¢£¬Ïêϸ°üÀ¨ÒÔÏÂÄÚÈÝ£º
×°ÖÃ΢ÐÅSDK
ÉèÖÃ΢ÐÅSDK
·¢ËÍÇëÇó
»ñȡ΢ÐÅ·µ»ØЧ¹û
ʾÀý´úÂë
×°ÖÃ΢ÐÅSDK
ʹÓÃComposer×°ÖÃ΢ÐÅSDK£¬Ö»ÐèÒªÖ´ÐÐÏÂÃæµÄÏÂÁ
composer require overtrue/wechat
µÇ¼ºó¸´ÖÆ
ÉèÖÃ΢ÐÅSDK
ÔÚconfigĿ¼ÏÂн¨wechat.phpÎļþ£¬È»ºóÌí¼ÓÒÔÏ´úÂ룺
<?php return [ 'app_id' => 'ÄãµÄAppID', 'secret' => 'ÄãµÄAppSecret', 'token' => 'ÄãµÄToken', ];
µÇ¼ºó¸´ÖÆ
ÆäÖÐapp_idºÍsecretΪ΢ÐÅ¿ª·¢ÕßÖÐÐĵÄÏà¹ØÐÅÏ¢¡£
·¢ËÍÇëÇó
ʹÓÃÏÂÃæµÄ´úÂë¿ÉÒÔ·¢ËÍÇëÇó£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
use EasyWeChatFactory; $config = [ 'app_id' => 'ÄãµÄAppID', 'secret' => 'ÄãµÄAppSecret', 'token' => 'ÄãµÄToken', ]; $app = Factory::officialAccount($config); $response = $app->qrcode->temporary($scene_id);
µÇ¼ºó¸´ÖÆ
Õâ¸öÀý×ÓʹÓÃÁËEasyWeChatÖеÄFactoryÀàÀ´¹¹½¨Î¢ÐÅAPIµÄʵÀý¡£qrcodeÊÇEasyWeChatÖеÄÒ»¸öAPI¶Ëµã£¬ÓÃÓÚ½¨Éè¶þάÂ룬temporaryÔòÊǸÃAPI¶ËµãϵÄÒ»¸öÒªÁì¡£
»ñȡ΢ÐÅ·µ»ØЧ¹û
EasyWeChat»á·µ»ØÒ»¸öÏìÓ¦¹¤¾ß¡£¿ÉÒÔͨ¹ýÒÔÏ´úÂë»á¼ûÏìÓ¦ÄÚÈÝ£º
echo $response->ticket; // »ñÈ¡¶þάÂëticket
µÇ¼ºó¸´ÖÆ
ʾÀý´úÂë
½¨ÉèÒ»¸öTestControllerÀ´²âÊÔ΢ÐÅSDK£º
<?php declare(strict_types = 1); namespace appcontroller; use thinknnotationInject; use EasyWeChatFactory; class Test { /** * @Inject * @var hinkApp */ protected $app; public function test() { $config = [ 'app_id' => 'ÄãµÄAppID', 'secret' => 'ÄãµÄAppSecret', 'token' => 'ÄãµÄToken', ]; $app = Factory::officialAccount($config); $response = $app->qrcode->temporary(123); echo $response->ticket; } }
µÇ¼ºó¸´ÖÆ
ÔÚä¯ÀÀÆ÷Öлá¼ûhttp://localhost/test/test½«¿´µ½Ò»¸ö¶þάÂëticket¡£
½áÓï
ÔÚThinkPHP6ÖÐʹÓÃ΢ÐÅSDKºÜÊÇÀû±ã£¬Ö»ÐèҪʹÓÃEasyWeChatÕâ¸ö¿â£¬¾Í¿ÉÒÔÇáËɵؼ¯³É΢ÐŹ¦Ð§¡£±¾ÎÄÏÈÈÝÁË×°Öá¢ÉèÖã¬ÒÔ¼°·¢ËÍÇëÇóºÍ»ñÈ¡ÏìӦЧ¹ûµÄÒªÁì¡£ÈôÊÇÄãÐèҪʹÓÃ΢ÐÅSDK¾ÙÐпª·¢£¬ÇëʵÑéÒ»ÏÂÕâ¸ö¿â¡£
ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃ΢ÐÅSDK£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡