LaneWeChat

PHP微信开发框架,高效开发微信公众号应用。简洁而又轻量

GitHub下载 查看手册

通过网页授权获得用户信息

Visits: 61640 Date: 2014-08-20 17:30:08 Power By 李轩Lane

    

        场景:用户点击了我的自定义菜单,或者我发送的文本消息中包含一个URL,用户打开了我的微信公众号的网页版,我需要获取用户的信息。


        代码:


        <?php

            use LaneWeChat\Core\WeChatOAuth;

            use LaneWeChat\Core\UserManage;


            //第一步,获取CODE

            WeChatOAuth::getCode('http://www.lanecn.com/index.php', 1, 'snsapi_base');

            //此时页面跳转到了http://www.lanecn.com/index.php,code和state在GET参数中。

            $code = $_GET['code'];

            //第二步,获取access_token网页版

            $openId = WeChatOAuth::getAccessTokenAndOpenId($code);

            //第三步,获取用户信息

            $userInfo = UserManage::getUserInfo($openId['openid']);

        ?>


Reply: ameson On 2015-01-16 14:46:53

Fatal error: Class 'test\LaneWeChat\Core\WeChatOAuth' not found in /var/www/html/test/getUserOpenid.php on line 7 php版本是5.3 请问这个怎么解决

回复

Reply: Lane On 2015-02-11 10:56:16

类没有找到。在/var/www/html/test/下面的文件中,include 'lanewechat\lanewechat.php'; 然后\LaneWeChat\Core\WeChatOAuth::方法()即可。

回复

Reply: ameson On 2015-01-16 17:58:45

Scope参数错误或没有Scope权限

回复

Reply: Lane On 2015-02-11 10:55:51

需要在微信后台开启网页授权的功能,并且填写URL。不要http,到.com截至。IP也可以。

回复

Reply: watson On 2015-03-27 11:24:50

WeChatOAuth::getCode('http://www.lanecn.com/index.php', 1, 'snsapi_base'); 请问getCode里面的参数我应该怎么写呢? 写一个新的页面404,本页也是404

回复

Reply: watson On 2015-03-27 11:57:56

找到原因了: 总结一下,给后面的卡在这朋友一个总结 config文件的URL没配置对。。。

回复

Reply: liweisheng On 2015-04-17 17:12:16

getCode('http://www.lanecn.com/index.php' getCode 里的跳转链接不要加上前面的域名如上面的www.lanecn.com

回复

Reply: Bob On 2015-04-24 16:00:34

你的代码会保存accesstoken,但是我用了新浪sae,没有写权限。这个怎么处理?

回复

Reply: Lane On 2015-06-16 10:17:28

sae不能写文件,所以你可以写数据库。

回复

Reply: yuhaol On 2015-04-29 17:28:35

授权页面刷新,code无效。此问题该如何解决。

回复

Reply: Lane On 2015-06-16 10:18:10

这个你要贴详细代码出来了

回复

Reply: Coomouse On 2015-06-11 12:05:18

你好,我用的1.4版的。网页获取用户openid,在微信用提示 redirect_uri 参数错误 <?php include 'lanewechat.php'; use LaneWeChat\Core\WeChatOAuth; use LaneWeChat\Core\UserManage; //第一步,获取CODE WeChatOAuth::getCode('lonyue.wicp.net/LaneWeChat/diansu.php', 1, 'snsapi_base'); //此时页面跳转到了http://www.lanecn.com/index.php,code和state在GET参数中。 $code = $_GET['code']; //第二步,获取access_token网页版 $openId = WeChatOAuth::getAccessTokenAndOpenId($code); //第三步,获取用户信息 $userInfo = UserManage::getUserInfo($openId['openid']); var_dump($userInfo); ?> 服务器都有配置正确

回复

Reply: Lane On 2015-06-16 10:19:15

redirect_uri要跳转到你自己的项目,。。。你跳到我博客干嘛=。=

回复

Reply: Coomouse On 2015-06-18 15:29:29

我是转到自己的项目的呀,只是没有改注释 WeChatOAuth::getCode('lonyue.wicp.net/LaneWeChat/diansu.php', 1, 'snsapi_base'); 我的自定义菜单代码如下: include 'lanewechat.php'; $menuList = array( array('id'=>'1', 'pid'=>'0', 'name'=>'点数', 'type'=>'view', 'code'=>'http://lonyue.wicp.net/LaneWeChat/diansu.php'), array('id'=>'2', 'pid'=>'0', 'name'=>'查询', 'type'=>'view', 'code'=>'http://lonyue.wicp.net/LaneWeChat/feedback.php'), array('id'=>'3', 'pid'=>'0', 'name'=>'更多', 'type'=>'', 'code'=>''), ); $result = \LaneWeChat\Core\Menu::setMenu($menuList); 服务器配置如下: define("WECHAT_URL", 'http://lonyue.wicp.net'); define('WECHAT_TOKEN', 'weixin'); define('ENCODING_AES_KEY', ""); diansu.php代码如下: include 'lanewechat.php'; use LaneWeChat\Core\WeChatOAuth; use LaneWeChat\Core\UserManage; //第一步,获取CODE WeChatOAuth::getCode('lonyue.wicp.net/LaneWeChat/diansu.php', 1, 'snsapi_base'); //此时页面跳转到了http://lonyue.wicp.net/LaneWeChat/diansu.php,code和state在GET参数中。 echo $code = $_GET['code']; //第二步,获取access_token网页版 $openId = WeChatOAuth::getAccessTokenAndOpenId($code); echo $openId; 还是出现 “redirect_uri 参数错误”,请大神帮我看一下,我只需要获取用户的ID就行了。

回复

Reply: caozewa On 2015-06-26 17:09:54

微信 开发者中心-》网页授权获取用户基本信息 -》修改 写上你的域名

回复

Reply: zokio On 2015-09-08 21:29:44

我在微信 开发者中心-》网页授权获取用户基本信息 -》修改 写上了我的域名www.huansiang.com 仍然是“redirect_uri 参数错误”

回复

Reply: caozewa On 2015-06-26 01:07:57

$openId = WeChatOAuth::getAccessTokenAndOpenId($code); $userInfo = UserManage::getUserInfo($openId['openid']); $openId 和$userInfo 获取到的怎么是数组呢

回复

Reply: WilliamLype On 2016-02-05 17:55:17

nice site!

回复

Reply: wxj2016 On 2016-03-21 21:35:54

我想获取用户信息,老是出错。那个WeChatOAuth::getCode()到底如何配置!!WECHAT_URL配哪个URL求解

回复

Reply: vikily On 2016-09-09 13:36:57

//发现个问题,需要把 $redirect_uri = WECHAT_URL . $redirect_uri; 注释掉,否则拼接的redirect_uri是错误的。 public static function getCode($redirect_uri, $state=1, $scope='snsapi_base'){ if($redirect_uri[0] == '/'){ $redirect_uri = substr($redirect_uri, 1); } //公众号的唯一标识 $appid = WECHAT_APPID; //授权后重定向的回调链接地址,请使用urlencode对链接进行处理 //$redirect_uri = WECHAT_URL . $redirect_uri; $redirect_uri = urlencode($redirect_uri);

回复

Reply: gujf On 2017-02-09 08:54:15

WeChatOAuth::getCode('http://www.lanecn.com/index.php', 1, 'snsapi_base'); 上面的代码里面的url其实是redirect_uri,所以只要2步: 1、去微信后台设置你的域名或者ip 2、这边的参数只要填写一个php文件名,WeChatOAuth::getCode('index.php', 1, 'snsapi_base'); ps: 1、这个问题也卡了我好久,后来仔细看了微信的官方文档,理解了原理,并看了作者的源码,亲测可以 2、评论有一个兄弟说要把wechatoauth里面的一个拼接的url注释掉,其实也没错,前提是redirect_uri要写完整的地址了 3、最后还有一点,确认你的config.php里面的相关参数是否正确,因为会读取里面的东西拼接url

回复

Reply: Nathaninove On 2021-09-23 14:03:09

Интернет разработки в SEO. О заработке в интернете: <a href=https://seo-zarabotoc.ru/prodvizhenie-v-internete/s.html>С++</a>

回复

Reply: generic cialis On 2021-10-03 22:34:38

cialis price <a href="https://cialiswithdapoxetine.com/#">cialis tablets</a>

回复

Reply: cialis generic On 2021-10-15 04:19:20

cialis 20 mg <a href="https://cialiswithdapoxetine.com/#">cialis coupon</a>

回复

Reply: cialis coupon On 2021-10-22 02:13:59

https://cialiswithdapoxetine.com/ cialis online

回复

Reply: can i take cialis with daxpoteine On 2021-10-25 03:40:53

<a href="https://cialiswithdapoxetine.com/#">fastest delivery of cialis</a> cheap cialis

回复

Reply: cialis support 365 On 2021-10-28 08:40:32

<a href="https://cialiswithdapoxetine.com/#">cialis black is it safe</a> cheap cialis

回复

Reply: cialis dosage On 2021-10-31 15:37:31

<a href="https://cialiswithdapoxetine.com/#">cialis coupon</a> cialis online

回复

Reply: cialis coupon On 2021-11-07 06:15:26

cialis alternative <a href="https://cialiswithdapoxetine.com/#">can i take cialis with daxpoteine</a>

回复

Reply: cialis pills On 2021-11-21 07:25:50

cialis alternative <a href="https://cialiswithdapoxetine.com/#">best prices for cialis 20mg</a>

回复

Reply: cialis price On 2021-11-24 13:33:04

buy cialis usa https://cialiswithdapoxetine.com/

回复

Reply: generic cialis On 2021-12-01 17:34:07

https://cialiswithdapoxetine.com/ cialis 20 mg

回复

Reply: best prices for cialis 20mg On 2021-12-05 16:22:34

cialis online https://cialiswithdapoxetine.com/

回复

Reply: cialis tablets On 2021-12-09 08:31:40

cialis without a doctor prescription <a href="https://cialiswithdapoxetine.com/#">cialis tadalafil & dapoxetine</a>

回复

Reply: cialis 20 mg On 2021-12-12 18:19:04

cialis dosage <a href="https://cialiswithdapoxetine.com/#">cialis generic</a>

回复

Reply: TimothyAdala On 2021-12-13 00:47:34

видео приколы про рыбалку <a href=https://zen.yandex.ru/video/watch/61ace0cf02e930708ab02d73>https://zen.yandex.ru/video/watch/61ace0cf02e930708ab02d73</a> Смешная видео нарезка для настроения <a href=https://zen.yandex.ru/video/watch/61ad7ec0273c2954487ee8ba>https://zen.yandex.ru/video/watch/61ad7ec0273c2954487ee8ba</a>

回复

Reply: can ubuy cialis on streets On 2021-12-17 04:07:58

buy cialis usa https://cialiswithdapoxetine.com/

回复

Reply: cialis without a doctor prescription On 2021-12-20 11:36:56

cialis dosage <a href="https://cialiswithdapoxetine.com/#">can i take cialis with daxpoteine</a>

回复

Reply: Frankbib On 2021-12-22 16:37:51

Запишись на БЕСПЛАТНЫЙ тренинг!!! !«СПЕЦИАЛИСТ ПО ИНТЕРНЕТ- РЕКЛАМЕ»! Регистрация здесь https://vk.cc/c9gMVV Участники получают СЕРТИФИКАТ о прохождении всех уроков и выполнении всех заданий тренинга. ссылка на регистрацию https://vk.cc/c9gMVV

回复

Reply: fastest delivery of cialis On 2021-12-26 10:30:27

cialis 20mg <a href="https://cialiswithdapoxetine.com/#">cialis 20 mg</a>

回复

Reply: best prices for cialis 20mg On 2021-12-30 11:04:28

<a href="https://cialiswithdapoxetine.com/#">cialis with dapoxetine overnight to</a> cialis tablets

回复

Reply: cialis online On 2022-01-04 02:31:28

<a href="https://cialiswithdapoxetine.com/#">cialis generic</a> buy cialis usa

回复

Reply: RonaldNar On 2022-01-12 09:58:03

<a href=http://www.youtube.com/watch?v=UNN48BSsp_w>Христианская песня Я счастлив со Христом</a>

回复

Reply: WillardSak On 2022-01-12 10:01:13

<a href=https://xristianin-world.blogspot.com/2022/01/blog-post_10.html>Христианская песня Я счастлив со Христом</a>

回复

Reply: JeffreyAdats On 2022-01-12 10:01:20

<a href=https://www.youtube.com/watch?v=UNN48BSsp_w>Христианская песня Я счастлив со Христом</a> <a href=http://www.youtube.com/watch?v=9sdwQrrZews>Песня Господь велик и достоин славы</a> <a href=https://xristianin-world.blogspot.com/2022/01/blog-post.html>Песня Господь велик и достоин славы</a> <a href=https://www.youtube.com/watch?v=9sdwQrrZews>Песня Господь велик и достоин славы</a> <a href=http://www.youtube.com/watch?v=UNN48BSsp_w>Христианская песня Я счастлив со Христом</a>

回复

Reply: DonaldbeX On 2022-01-14 20:36:07

https://vk.com/rabota_kemer_ovo

回复

Reply: DonaldbeX On 2022-01-16 05:41:55

https://vk.com/rabota_kemer_ovo?w=wall-109862666_2779

回复

Reply: Michaelhaimi On 2022-01-17 00:08:43

https://images.google.co.ls/url?sa=t&url=https://vk.com/zarabotok_v_internete_dlya_mam

回复

Reply: JeffreyAdats On 2022-01-23 13:31:43

<a href=https://zen.yandex.ru/video/watch/61ea2eb6b067c55d21f99893>Ходить во свете</a>

回复

Reply: Rubenmat On 2022-01-25 11:06:25

<a href=https://www.youtube.com/watch?v=Y4x8LV9PnOg&t=2s>Лучшие Игры Стратегии</a>

回复

Reply: BobbyBooky On 2022-01-25 11:22:36

<a href=https://zen.yandex.ru/media/id/61a747d35d05e073f4def2f9/chto-takoe-backlinks-obratnye-ssylki-61a87c71f355f219fd087990>обратные ссылки</a>

回复

Reply: Michaelhaimi On 2022-01-26 00:26:57

<a href=https://maps.google.com.ec/url?sa=t&url=https://vk.com/zarabotok_v_internete_dlya_mam>хороший заработок в интернете с вложениями</a>|

回复

Reply: BrandonPelry On 2022-01-26 00:35:49

https://images.google.ne/url?sa=t&url=http://xn-----7kccgclceaf3d0apdeeefre0dt2w.xn--p1ai/pismennyie-perevodyi-novokuznetsk.php

回复

Reply: TloWT On 2022-02-02 01:47:03

<a href="https://seroquel4all.top">buy generic seroquel</a>

回复

Reply: Roberttof On 2022-02-05 23:10:07

<a href=http://www.youtube.com/watch?v=laT3nvzDjl8>Funny animal videos</a>

回复

Reply: Patrickgeamn On 2022-02-06 10:24:47

We will help you promote your site, backlinks for the site are here inexpensive <a href=http://links-for.site>www.links-for.site</a>

回复

Reply: FrusyassunDa On 2022-02-09 01:12:08

<a href="https://stromectoleth.com/">ivermectin virus </a>

回复

Reply: Thorsten On 2022-05-09 21:14:28

I absolutely love your blog and find most of your post's to be precisely what I'm looking for. Would you offer guest writers to write content to suit your needs? I wouldn't mind producing a post or elaborating on some of the subjects you write related to here. Again, awesome site! darknet markets https://market-darknet.com

回复

Reply: Thorsten On 2022-05-09 21:14:48

I absolutely love your blog and find most of your post's to be precisely what I'm looking for. Would you offer guest writers to write content to suit your needs? I wouldn't mind producing a post or elaborating on some of the subjects you write related to here. Again, awesome site! darknet markets https://market-darknet.com

回复

Reply: Thorsten On 2022-05-09 21:15:04

I absolutely love your blog and find most of your post's to be precisely what I'm looking for. Would you offer guest writers to write content to suit your needs? I wouldn't mind producing a post or elaborating on some of the subjects you write related to here. Again, awesome site! darknet markets https://market-darknet.com

回复

Reply: Roxanna On 2022-05-12 21:35:56

I have read so many articles concerning the blogger lovers but this paragraph is in fact a good article, keep it up. darkmarket https://mydarkmarket.com

回复

Reply: Mitch On 2022-05-14 00:26:13

My brother suggested I might like this website. He used to be totally right. This post truly made my day. You can not believe simply how so much time I had spent for this info! Thanks! dark web Market list https://market-darknet.com

回复

Reply: Valentin On 2022-05-18 00:30:34

Amazing! Its truly awesome paragraph, I have got much clear idea on the topic of from this paragraph. best darknet markets https://mydarkmarket.com

回复

Reply: jbufwosc On 2022-05-23 07:47:34

<a href="http://erythromycin1m.com/#">erythromycin cream for acne</a>

回复

Reply: Kareem On 2022-05-24 12:13:13

Oh my goodness! Impressive article dude! Thank you, However I am having difficulties with your RSS. I don't understand the reason why I am unable to subscribe to it. Is there anyone else having the same RSS problems? Anyone that knows the solution will you kindly respond? Thanx!! dark web market links https://mydarkmarket.com

回复

Reply: Audra On 2022-05-24 21:08:45

great issues altogether, you just received a logo new reader. What could you suggest about your put up that you made a few days in the past? Any sure? darkmarket https://asap-onion.com

回复

Reply: Birgit On 2022-05-26 17:21:35

My relatives all the time say that I am wasting my time here at net, however I know I am getting knowledge every day by reading such fastidious posts. darknet market links https://asap-markett.com

回复

Reply: wzbyglff On 2022-05-27 23:05:21

<a href="http://erythromycinn.com/#">erythromycin ophthalmic ointment</a> azithromycin and erythromycin

回复

Reply: Nichole On 2022-06-02 02:39:52

I'm impressed, I must say. Rarely do I encounter a blog that's both educative and engaging, and let me tell you, you have hit the nail on the head. The problem is something which too few men and women are speaking intelligently about. I am very happy I came across this during my hunt for something regarding this. darknet websites https://dark-markets-btc.com

回复

Reply: Bruno On 2022-06-06 22:24:58

I'm not sure where you're getting your information, but good topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic information I was looking for this information for my mission. best darknet markets https://darkmarketbot.com

回复

Reply: Tracey On 2022-06-10 15:06:20

This paragraph is in fact a good one it helps new the web users, who are wishing for blogging. darkmarket https://market-darknet.com

回复

Reply: antibioticsDully On 2022-06-12 17:41:52

Also, whitman-walker clinic of suburban maryland closes on sept. the quick antibiotics delivery remains a electricity and ranching lifestyle. no prescription antibiotics Fedex delivery cheap antibiotics in india <a href="http://www.nieuws.top010.nl/wp-content/uploads/cms/buy-antibiotics-online/">Buy Cheap antibiotics Online Overnight</a> Excellent Online Service, Buy antibiotics without script Needed antibiotics onlines au.

回复

Reply: Jameswacw On 2022-06-19 09:03:49

Hello mates, its impressive post about educationand completely defined, keep it up all the time. see also my sites https://bitcoinup76431.gynoblog.com/13411237/facts-about-money-transfer-revealed About bitcoin price <a href=https://rickeyi196txa7.vigilwiki.com/user>Not known Details About money exchange </a> https://mikhaild084qux6.therainblog.com/profile money 24 - An Overview <a href=https://cesarafjln.blogdosaga.com/12060487/bitcoin-mixing-service-for-dummies>New Step by Step Map For bitcoin cash</a> https://madesocials.com/story12777371/the-single-best-strategy-to-use-for-money-x moneyfarm login Options <a href=https://bookmarkinglog.com/story12513226/finance-kitchens-secrets>bitcoin mixing service for Dummies</a> https://tripsbookmarks.com/story12650506/not-known-details-about-bitcoin-tumbler How Much You Need To Expect You'll Pay For A Good moneyfarm <a href=https://livebookmarking.com/story12648145/5-easy-facts-about-bitcoin-tumbling-described>Not known Details About money exchange </a> https://bookmarkassist.com/story12595797/not-known-facts-about-bitcoin-euro The Ultimate Guide To money for nothing <a href=https://josueruwya.smblogsites.com/11896835/bitcoin-blender-an-overview>The Single Best Strategy To Use For money lisa</a> https://torgovaya.xyz/exchange =ddd=9+

回复

Reply: baclofenDot On 2022-07-09 12:54:57

In 2011, a Buy baclofen online without prescription overnight found against burzynski in a size of advertising analgesic. baclofen Buy Online USA <a href="http://www.nieuws.top010.nl/wp-content/uploads/cms/buy-baclofen-online/">get baclofen online</a> Fda Approvals, allergic reaction to baclofen discountt baclofen.

回复

Reply: Sharyn On 2022-08-04 15:13:41

Hmm is anyone else experiencing problems with the pictures on this blog loading? I'm trying to figure out if its a problem on my end or if it's the blog. Any feedback would be greatly appreciated. darkmarket 2022 https://marketdarkweb.com

回复

Reply: Lelia On 2022-08-14 21:00:26

If you are going for finest contents like myself, simply pay a visit this site every day because it presents feature contents, thanks darkmarket list https://alphabay-darknet.net

回复

Reply: Bernard On 2022-08-15 02:35:45

What a material of un-ambiguity and preserveness of precious knowledge regarding unpredicted feelings. dark web market links https://alphabay-darknet.net

回复

Reply: Emelia On 2022-08-17 08:03:16

I want to to thank you for this fantastic read!! I definitely loved every bit of it. I have got you book-marked to check out new stuff you post… Dark Market List https://alphabay-darkweb.com

回复

Add Comment
©2014~time() lanewechat.lanecn.com , All rights reserved. Power By LaneWeChat 微信PHP开发框架.  京ICP备14005030号-1