GithubHelp home page GithubHelp logo

wechat-sdk's Introduction

又拍云微信小程序 SDK

又拍云 微信小程序 SDK,帮助你在存储空间、资源存放、访问加速、资源处理等方面进行大幅优化,为微信小程序提供扩容、加速解决方案。

使用

使用方式可以参考 demo

  1. 登录微信小程序账户并配置 uploadFile 合法域名为 https://v0.api.upyun.com
  2. 软链 upyun-wxapp-sdk.js 到微信小程序项目
  3. 通过 require 引入 Upyun 类,并初始化一个实例
  4. 调用 upyun.upload 方法上传文件

运行 Demo

下载微信小程序开发工具

增加 demo 目录为新项目

add-project

运行服务器进程

npm run demo

接口

Upyun

  • bucket: 空间名
  • operator: 操作员
  • getSignatureUrl: 计算 signature 的服务器接口地址

示例

const upyun = new Upyun({
  bucket: 'sdkimg',
  operator: 'tester',
  getSignatureUrl: 'http://localhost:8080',
})

Upyun.prototype.upload

  • remotePath 在又拍云存储的文件路径
  • localPath 本地文件路径
  • success 接口调用成功的回调函数
  • fail 接口调用失败的回调函数
  • complete 接口调用结束的回调函数(调用成功、失败都会执行)
upyun.upload({
  localPath: imageSrc,
  remotePath: '/wxapp/demo',
  success: function(res) {
  },
  fail: function({errMsg}) {
  },
})

服务器接口

使用又拍云微信小程序 SDK 需要实现一个在服务器进行签名的接口,并将该接口地址作为 getSignatureUrl 传入构造函数,

该接口接受 GET 请求,并接受一个参数 data,计算并返回带有 signature 字段的响应

signature 的计算公式是

Base64 (HMAC-SHA1 (<md5_password>, <data>)

其中,md5_password 是操作员密码的 MD5 值

相关链接

wechat-sdk's People

Contributors

cattail avatar

Watchers

 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.