首页 > 编程知识 正文

php开发微信公众号,微信订阅号php配置

时间:2023-05-05 13:49:33 阅读:28496 作者:4499

本文介绍微信开发微信发布平台、网络授权和40029问题解决方案。 希望这篇文章对学习微信有帮助。

1、跳转授权链接

3359 open.weixin.QQ.com/connect/oauth2/authorize? appid=XXX redirect _ uri=XXX response _ type=code scope=snsapi _ userinfo state=state connect _ redirect=1# we chat

最初不添加参数connect_redirect=1,而是始终使用{'errcode':40029,' errmsg':'invalidcode,hints : [ req _ 365292; 代码很好。

第二,请注意redirect_uri=xxx需要自己的URL转码

2、获取用户信息,直接上传到代码上。

用户系统; using系统. web; using Newtonsoft.Json.Linq; using System.Net; using System.IO; using System.Text; publicclassgetinfos : ihttphandler { publicvoidprocessrequest (httpcontext context )//全部从这里开始string code=context.requext 内容. response.write (getinfos ) code ); } publicboolisreusable { get { return false; } publicstringgetinfos (string _code )/string_access_tokens=gettoken ) _ code ); jobject JSON=jobject.parse (access _ tokens ); string access _ token=JSON [ ' access _ token ' ].tostring (; string refresh _ token=JSON [ ' refresh _ token ' ].tostring (; string OpenID=JSON [ ' OpenID ' ].tostring (; //string _ infos=get userinfo (access _ token,openid ); jobject info=jobject.parse (_ infos; If (信息代码)!=null } { _ access _ tokens=refresh token (refresh _ token ); JSON=jobject.parse (access _ tokens ); access _ token=JSON [ ' access _ token ' ].tostring (; openid=json['openid'].ToString (; _ infos=get userinfo (access _ token,openid ); } return _infos; /////code中的token//privatestring gettoken (string _ code ) (if ) code.indexof ) () () () () ) (code )=ssode string RequestPara=? appid=xxx '; RequestPara ='secret=xxx '; 请求para=' code=' _ code; request para=' grant _ type=authorization _ code '; string _ access _ tokens=get data (URL,请求para ); _ access _ tokens=_ access _ tokens.replace ('','''); return _access_tokens; } //////获取用户信息///privatestringgetuserinfo (string access _ token,string openid ) if ) access_token.indexof stringi _ URL=' https://API.weixin.QQ.com/SNS/userinfo '; string I_RequestPara='? access_token=' access_token; I_RequestPara ='openid=' openid; I_RequestPara ='lang=zh_CN '; string_infos=getdata(I_URL,I_RequestPara ); _infos=_infos.replace(''、'''); return _infos; (///token//privatestringrefreshtoken (string refresh _ token ) if(refresh_token.indexof ) ) () () string R_RequestPara=? appid=xxx '; r _ request para=' grant _ type=refresh _ token '; r _ request para=' refresh _ token=' refresh _ token; string_infos=getdata(r_URL,R_RequestPara ); _infos=_infos.replace(''、'''); return _infos; } //////访问地址,//privatestring get data (string URL,string RequestPara ) request para=request para.index of ) (请求para ) : ) (? 请求帕ra; webrequest HR=http webrequest.create (urlrequestpara ); byte [ ] buf=system.text.encoding.get encoding (' utf-8 ' ).getbytes ) requestpara ); hr.Method='GET '; system.net.webresponse response=HR.getresponse (; streamreader reader=new streamreader (response.getresponse stream ),encoding.getencoding('utf-8 ' )字符串返回reader.Close (; response.Close (; 返回返回返回; }

本文职位坐标整理发表,希望对同学们有帮助。 更多信息,请关注职位坐标移动开发微信频道!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。