博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于WechatApp学习总结
阅读量:5751 次
发布时间:2019-06-18

本文共 2643 字,大约阅读时间需要 8 分钟。

package cn.simo.web.servlet;

import java.io.IOException;

import java.sql.SQLException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import cn.simo.*;
import cn.simo.service.UserService;
/**
* Servlet implementation class GetOpenId
*/
public class BindWechatServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BindWechatServlet() {
super();
}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// String code = request.getParameter("code");
// HttpGet httpGet = new HttpGet("https://api.weixin.qq.com/sns/jscode2session?appid="+Configure.getAppID()+"&secret="+Configure.getSecret()+"&js_code="+code+"&grant_type=authorization_code");
// //鐠佸墽鐤嗙拠閿嬬湴閸c劎娈戦柊宥囩枂
// HttpClient httpClient = HttpClients.createDefault();
// HttpResponse res = httpClient.execute(httpGet);
// HttpEntity entity = res.getEntity();
// String result = EntityUtils.toString(entity, "UTF-8");
response.setContentType("text/html;charset=utf-8");
String phone = request.getParameter("phone");
String openid = request.getParameter("openid");
// String openid=result;
String status="";
try {
int i = new UserService().bindWechat(openid,phone);
}catch (SQLException e) {
status = "{status:2}";
response.getWriter().append(status);
e.printStackTrace();
System.out.println("ERROR!");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
* status:
* 0 --- 缁戝畾澶辫触
* 1 --- 缁戝畾鎴愬姛
* 2 --- 缃戠粶寮傚父锛岃绋嶅悗鍐嶈瘯
*/
if(openid!=null) {
status = "{status:1}";
response.getWriter().append(status);
} else {
status = "{status:0}";
response.getWriter().append(status);
// }

}

}

 

 

 

 

 

 

 

 

 

 

 

 

微信小程序是以https方式提交数据到你的后台,如下:

wx.request({
url: 
'test.php'
//你的后台地址
data: {
x: 
'' 
,
y: 
''
},
header: {
'content-type'
'application/json'
},
success: 
function
(res) {
console.log(res.data)
}
})
 

转载于:https://www.cnblogs.com/zysys/p/8039524.html

你可能感兴趣的文章
采购申请转采购订单错误:在语言EN中没有维护短文本(请重维护物料460300080)
查看>>
Migration to S/4HANA
查看>>
SAP WM LPK1 不能把 cross-material control cycles定义成release order parts
查看>>
HTML5 & CSS3初学者指南(3) – HTML5新特性
查看>>
linux redhat 添加硬盘并挂载
查看>>
闯过这 54 关,点亮你的 Git 技能树
查看>>
linux从零开始
查看>>
cisco命令大全(清除配置和恢复口令)
查看>>
计算机操作系统(第四版)课后习题答案(完整版)
查看>>
Java 基础(2)运算符
查看>>
正则表达式全部符号解释
查看>>
单片机进修的预备任务
查看>>
NSD1710-exec01
查看>>
什么是架构(解决人的问题,人的角度)
查看>>
Linux学习笔记第八周五次课(3月30日)
查看>>
红帽6.5系统---封装虚拟机
查看>>
zg手册 之 scrapy 开发(4)-- javascript 动态页面的抓取
查看>>
HCNA——动态路由协议基础
查看>>
MongoDB3.4 shell CRUD操作
查看>>
Java XML DOM解析(xPath)
查看>>