Giter VIP home page Giter VIP logo

bytedance-open-demo's Introduction

ByteDance-Open-Demo

  • 字节跳动小程序第三方接入文档
  • 该demo为ByteDanceOpen SDK用法示例. 大部分参数和url跟字节跳动open api保持相同, 方便对照文档快速理解使用, 剩余的按照RESTful命名风格
  • 提供了docker启动方式,包含redis和ngrok服务
  • 当前页面上的图片如果裂了,可以尝试修改host,如果还不行那么就需要科学上网o( ̄ヘ ̄o#),或者clone后查看images/gifs文件夹下对应的图片
  • 如果觉得用起来还不错╰(●’◡’●)╮,希望能够star🌟支持一下~~~
  • 如果有接口没有及时更新,可以给我提issue或者PR,着急的话也可以通过sdk暴露的接口自己实现(详情见下面的其他注意事项)。

申请账号

配置ip白名单

启动项目

方式1: docker启动方式

1. 进入项目目录

  cd /yourpath/bytedance-open-demo

2. 打包jar

  mvn clean install -DskipTests

3. 在docker-compose.yml中填入第三方平台的信息

4. 通过docker启动所需服务: redis,ngrok以及本项目

  docker-compose up --build

5. 获取本机外网地址: 查询ngrok提供的外网地址

Mac
curl $(docker port bytedance-open-demo_ngrok_1 4040)/api/tunnels
Windows

两种方式都可以从public_url中找到所需的外网地址

6. 配置 授权发起页域名,授权接收URL,消息与事件接收URL

方式2: 普通启动方式

1. 启动redis

  • access_token等数据都是保存在redis中,所以需要一个redis服务

  • 为了方便使用,项目中提供了一个默认的redis.conf, 位于docker/redis/redis.conf, 只修改了两个配置:

    # 把protected-mode改为了no
    protected-mode no
    # 注释了bind
    # bind 127.0.0.1 ::1
  • 本项目使用的redis客户端是redisson,可以直接使用。如果想修改redis连接相关配置,可以在application-dev.yml指定redis的配置文件。

  • 如果想要使用jedis,可以自己实现一个IByteDanceRedisOps

2. 获取本机外网地址: 内网穿透

  • 如果没有公网地址,那么需要使用内网穿透工具。比如ngrok
  • 如果使用ngrok,下载好后,根据不同的操作系统,在命令行执行
      # MacOS
      ngrok http 8080
      # Windows
      ngrok.exe http 8080
    就能得到一个映射到8080端口(项目默认启动端口)的外网地址。

3. 配置 授权发起页域名,授权接收URL,消息与事件接收URL

4. 启动本项目

  • 启动项目后需要等待字节跳动服务器将ticket推送过来后(一般10分钟以内),才能进行后续的授权等api调用。如果一直没有推送,请到字节跳动第三方平台,选择自己创建的第三方平台确认推送地址是否配置正确 image

任选一种方式启动项目后,进行接口测试

事件推送处理

  • 可以在EventHandlerConfiguration配置用于处理相应事件的handler

单元测试

  1. 启动项目

  2. 进行小程序授权

  3. 配置src/test/resources/application-unittest.yml中的

bytedance:
  open:
    componentAppId: ""
    componentSecret: ""
    componentToken: ""
    componentAesKey: ""
  1. 将刚才授权的小程序appid配置到src/test/resources/application-unittest.yml中的
test-app-info:
  appid: ""
  1. 运行单元测试

其他注意事项

  • 加解密异常 java.security.InvalidKeyException: Illegal key size
  • 目前字节跳动的字节跳动开放平台文档还在不断更新,我也会根据他的更新不断新增接口。如果有接口没有及时更新,可以给我提issue或者PR,着急的话也可以通过sdk暴露的接口自己实现。 image

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.