当前位置: 首页 > news >正文

手机号码定位网站开发搜索引擎推广和优化方案

手机号码定位网站开发,搜索引擎推广和优化方案,有什么网站可以做运动鞋,个人网站怎么做微信支付首先准备一个已经认证的微信公众号 假如没有已经认证的,就可以使用 公众平台测试账号 进行开发 https://mp.weixin.qq.com/cgi-bin/frame?tadvanced/dev_tools_frame&nav10049&token1939537199&langzh_CN 然后看: 点击 进入,查…

首先准备一个已经认证的微信公众号

假如没有已经认证的,就可以使用 公众平台测试账号 进行开发

https://mp.weixin.qq.com/cgi-bin/frame?t=advanced/dev_tools_frame&nav=10049&token=1939537199&lang=zh_CN

然后看:

 

点击 进入,查看此接口的开发说明文档。

https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842

 

 

 

大概有4步 

1 第一步:用户同意授权,获取code2 第二步:通过code换取网页授权access_token3 第三步:刷新access_token(如果需要)4 第四步:拉取用户信息(需scope为 snsapi_userinfo)5 附:检验授权凭证(access_token)是否有效

 

下面进行代码的开发:

新建一个项目:WxAuth

下面编写一个工具类:

根据地址进行网络请求的

需要的jar包

 

/WxAuth/src/com/wx/auth/util/AuthUtil.java

package com.wx.auth.util;import java.io.IOException;import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;import net.sf.json.JSONObject;public class AuthUtil {public static final String APPID = "wxa2021f7d0c2259f9";public static final String APPSECRET = "be070e2d7ee644aaa845f81f2cd847b2";public static JSONObject doGetJson(String url) throws ClientProtocolException, IOException{JSONObject jsonObject = null;DefaultHttpClient client = new DefaultHttpClient();HttpGet httpGet = new HttpGet(url);HttpResponse response = client.execute(httpGet);HttpEntity entity = response.getEntity();if(entity != null){String result = EntityUtils.toString(entity,"UTF-8");jsonObject = JSONObject.fromObject(result);}httpGet.releaseConnection();return jsonObject;}
}

 

下面组装一个接口地址:

 

1 第一步:用户同意授权,获取code

 

https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect

/WxAuth/src/com/wx/auth/util/LoginServlet.java

package com.wx.auth.servlet;import java.io.IOException;
import java.net.URLEncoder;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@WebServlet("/wxLogin")
public class LoginServlet extends HttpServlet{protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {//回调地址,需公网能访问String backUrl = "http://huanglianggu.s1.natapp.cc/WxAuth/callBack";String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+AuthUtil.APPID  + "&redirect_uri="+URLEncoder.encode(backUrl)+ "&response_type=code" + "&scope=snsapi_userinfo" + "&state=STATE#wechat_redirect";resp.sendRedirect(url);}
}

 

第二步:通过code换取网页授权access_token

获取code后,请求以下链接获取access_token:  https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code

/WxAuth/src/com/wx/auth/servlet/CallBackServlet.java

package com.wx.auth.servlet;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONObject;import com.wx.auth.util.AuthUtil;@WebServlet("/callBack")
public class CallBackServlet extends HttpServlet{protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {String code = req.getParameter("code");String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+AuthUtil.APPID+ "&secret="+AuthUtil.APPSECRET+ "&code="+code+ "&grant_type=authorization_code";// 进行网络请求JSONObject jsonObject = AuthUtil.doGetJson(url);String openid = jsonObject.getString("openid");String token = jsonObject.getString("access_token");// 第四步:拉取用户信息(需scope为 snsapi_userinfo)//String infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";String infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+token+"&openid="+openid+"&lang=zh_CN";// 进行网络请求JSONObject userInfo = AuthUtil.doGetJson(infoUrl);System.out.println("userInfo = "+userInfo);super.doGet(req, resp);}
}

再创建一个页面

/WxAuth/WebContent/index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width-device-width,initial-scale-1.8">
<title>Insert title here</title>
</head>
<body style="font-size:45px;text-align:center;"><a href="/WxAuth/wxLogin">微信公众授权登录</a>
</body>
</html>

启动项目

浏览器访问:

http://huanglianggu.s1.natapp.cc/WxAuth/index.jsp

 

如果浏览器点击 则会提示

需要手机登录

手机上点击登录后,提示:

                                     

 

需要到 https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

修改:

 

点击 修改

 

手机点击登录,控制台是输出想要的结果了。

但是,回调页面报错:

 

直接跳转到 resp.sendRedirect("http://www.baidu.com");  

	@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {String code = req.getParameter("code");String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+AuthUtil.APPID+ "&secret="+AuthUtil.APPSECRET+ "&code="+code+ "&grant_type=authorization_code";// 进行网络请求JSONObject jsonObject = AuthUtil.doGetJson(url);String openid = jsonObject.getString("openid");String token = jsonObject.getString("access_token");// 第四步:拉取用户信息(需scope为 snsapi_userinfo)//String infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";String infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+token+"&openid="+openid+"&lang=zh_CN";// 进行网络请求JSONObject userInfo = AuthUtil.doGetJson(infoUrl);System.out.println("userInfo = "+userInfo);resp.sendRedirect("http://www.baidu.com");//super.doGet(req, resp);}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.wooajung.com/news/33869.html

相关文章:

  • wordpress 菜单 颜色如何优化网络连接
  • 购物网站建设存在的问题武汉武汉最新
  • 网站建立服务seo关键词使用
  • 网站策划书主题哈尔滨seo网站管理
  • 资讯型电商网站优缺点kol推广
  • 旅游网站建设的方向qq空间刷赞网站推广
  • 网站建设公司的业务规划建设一个网站的具体步骤
  • 青岛建站开发网络品牌推广
  • 网站的百度推广怎么做百度广告代理商
  • 短视频素材下载网站 免费电脑优化软件推荐
  • wordpress wp roket青岛关键词优化平台
  • 二次开发和一次开发哪个好深圳seo优化排名推广
  • 想做个网站不知道做什么网络推广优化品牌公司
  • 村级网站建设系统品牌整合营销传播
  • 免费制作logo的软件有哪些seo标题关键词优化
  • wordpress构建企业网站黄页88网站推广效果
  • 网站需要前台后台青岛百度网站排名
  • 巩义做网站xd seo百度广告联盟平台官网
  • 沧县网站建设公司谷歌外链代发
  • 搭建网站有什么用成都网站建设软件
  • 网站推广优化方案模板市场推广方式有哪几种
  • 怎么设计网络营销方案网站优化seo是什么意思
  • 网站建设与维护典型案例漳州seo网站快速排名
  • WordPress网站被恶意登录网络培训心得体会
  • 如何建立动态网站软文推广做得比较好的推广平台
  • 软件下载网站制作手机广告推广软件
  • 半成品代加工接订单平台seo排名培训
  • tp5网站开发逻辑架构百度seo指南
  • 宝安网站建设哪家便宜东莞seo优化排名推广
  • 婚纱摄影网站的设计南召seo快速排名价格