微信公众平台开发模式通用接口API(Weixin)
is a PHP (>= 5.3) client library for the 微信公众平台开发模式通用接口API(Weixin)
Loading the library
Weixin relies on the autoloading features of PHP to load its files when needed and complies with the PSR-0 standard which makes it compatible with most PHP frameworks. Autoloading is handled automatically when dependencies are managed using Composer, but you can also leverage its own autoloader if you are going to use it in a project or script without any PSR-0 compliant autoloading facility:
// Prepend a base path if Weixin is not available in your "include_path". require 'Weixin/Autoloader.php'; WeixinAutoloader::register();
It is possible to easily create a phar archive from
the repository just by launching bin/create-phar
. The generated phar contains a stub defining an
autoloader function for Weixin, so you just need to require the phar to start using the library.
Alternatively, it is also possible to generate one single PHP file that holds every class like older
versions of Weixin by launching bin/create-single-file
, but this practice is not encouraged.
调用事例
try { $appid="xxxxxxxxxxxx";//appID $secret="xxxxxxxxxxxx";//appsecret //如果之前获得access_token,那么在生成WeixinClient对象的时候,直接指定 //$access_token = "RWRVPpT1O9SEyN615puzCOQ9uQfgQK0SA63gWUxNo2ABjgHFdnCL82BnFB_wQGeZH4prBLfn17Qz0WSwcwdLW6A2YvX1yN46dDB2-BggdXkqpM0AZXO4lfZ0LSC_5ABj8NxKLxJkqv565EBja32Gpw"; //$client = new WeixinWeixinClient($appid,$secret,$access_token); //如果之前没有获得过access_token,那么通过getAccessToken方法 获取access_token $client = new WeixinWeixinClient($appid,$secret); $rst = $client->getAccessToken(); $access_token = $rst['access_token']; echo $access_token; echo "<br/>"; $openid="xxxxxxxxxxxxxxx"; //发送客服文本消息 $client->getWeixinMsgManager()->getWeixinCustomMsgSender()->sendText($openid, "测试"); //下载多媒体文件 $mediaId= "xxxxxxxxxxxxxxx"; $ret= $client->getWeixinMediaManager()->get($mediaId); $fileContent = base64_decode($ret['content']); $tmpfname = sys_get_temp_dir().'/'.uniqid().'.jpg'; //保存在本地 file_put_contents($tmpfname, $fileContent); //获取微信用户信息 $userinfo =$client->getWeixinUserManager()->getUserInfo($openid); print_r($userinfo); echo "<br/>"; //生成ticket $scene_id =1; $ticketInfo = $client->getWeixinQrcodeManager()->create($scene_id,false); print_r($ticketInfo); echo "<br/>"; //获取ticket $ticket = urlencode($ticketInfo['ticket']); $url = $client->getWeixinQrcodeManager()->getQrcodeUrl($ticket); echo $url; echo "<br/>"; } catch (Exception $e) { echo($e->getMessage()); }
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。