GithubHelp home page GithubHelp logo

hhy5277 / springboot-weapp-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nosqlcoco/springboot-weapp-demo

0.0 2.0 0.0 62 KB

微信小程序服务端接口,支持普通Http请求、上传文件、长连接。

Java 100.00%

springboot-weapp-demo's Introduction

springboot-weapp-demo

微信小程序服务端接口,支持普通Http请求、上传文件、长连接,微信登录及敏感数据解密。后台服务使用springboot框架搭建,mongodb做数据库,redis做缓存。

运行环境:JDK8+

注意:如果你是本地运行,需要修改为你本地对应的主机和端口。 长连接需使用ws协议

####更新日志:

  • 2016-12-18

    • 拦截器记录口访问日志存储mongodb
  • 2016-11-24

    • 小程序code换取session_key和openid
    • 小程序登录用户敏感数据解密
  • 2016-11-22

    • 配置Https
  • 2016-11-18

    • 重写小程序http测试和上传文件接口
    • 统一接口返回返回状态码和格式
  • 2016-11-20

    • 添加Redis缓存
    • 添加微信登录状态维护和用户数据解密接口

一、测试小程序wx.request接口

wx.request({
	url: 'http://localhost:9090/weappservice/api/v1/user/get/{id}',
	
    data: {appId: 'JWEJIJ345QHWJKENVKF', apiName: 'GET_USER'},
    
    method: 'GET',
    
    //return JSON format,like: {"id":"{id}"}
    success: function(res){
		console.log(res.data);
    },
    fail: function(res){
    
    },
    complete: function(res){
    
    }
});

二、测试小程序wx.uploadFile接口,单张上传

wx.uploadFile({
    url: 'http://localhost:9090/weappservice/api/v1/upload/image',
    
    //文件临时路径
    filePath: tempFilePath,
    
    name: 'file',
    
    header: {},
    
    formData: {appId: 'JWEJIJ345QHWJKENVKF', apiName: 'UPLOAD_IMAGE'},
    
    success: function(res){
      console.log(res.data)
    },
    
    fail: function(res){
    
    },
    
    complete: function(res){
    
    }
})
状态码(errcode) 说明(msg)
0 图片路径
40010 请选择上传文件!
40011 文件上传失败

三、测试小程序websocket相关接口

//发起websocket连接
wx.connectSocket({
	url: 'ws://localhost:9090/weappservice/websocket?name=xiaoqiang',
  	//这里写了参数,但是参数没有发送出去,大家可以试试,已经邮件反馈微信团队了,等待回复。所以把参数拼接在url后面。
  	data: {
  		'name1': 'xiaoqiang1'
  	}
}),

//监听打开事件
wx.onSocketOpen(function(res) {
  	console.log('WebSocket连接已打开!');
}),

//接收消息,接收的消息是json字符串,需要JSON.parse转成JSON对象
wx.onSocketMessage(function(res){
	var data = JSON.parse(res.data);
	console.log(data);
}),

//发送消息,消息对象属性key(user和content)不能自定义。
wx.sendSocketMessage({
    data: JSON.stringify({
      user: 'xiaoqaing',
      content: 'Hi, My name is xiaoqiang'
    }),
    success: function(res){
    	console.log('消息发送成功!')
    }
})

我的微信小程序DEMO:weixin_smallexe

PS:我的公众号:

springboot-weapp-demo's People

Contributors

nosqlcoco avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.