Rubymotion gem to easily use WeChatSDK
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
lib
spec
vendor
.gitignore
Gemfile
Gemfile.lock
README.md
Rakefile
motion-wechat.gemspec

README.md

WechatSDK for RubyMotion

Code Climate

This is a RubyMotion gem for WechatSDK to integrate WeChat API with your RubyMotion app. See http://dev.wechat.com/wechatapi/documentation

Setup

Add MotionWechat to your Gemfile, and run bundle install:

gem 'motion-wechat'

Edit the Rakefile of your RubyMotion project and add the following require line:

# After the line that require Rubymotion
require 'bundler'
Bundler.require

Then setup configuration in your Rakefile:

MotionWechat::Config.setup(app, 'app_key', 'app_secret')

Then register app in your app_delegate.rb

MotionWechat::API.instance.registerApp

Usage

Basic:

MotionWechat::API.instance.send_webpage "http://www.rubymotion.com", \
  title: "Ruby Motion", description: "Awesome way to write ios/osx app"

Wechat Authorization:

1. authorize, this will direct user to wechat app

MotionWechat::API.instance.authorize

2. then make sure you have weixin delegate set up in app_delegate.rb

def application(application, handleOpenURL:url)
  WXApi.handleOpenURL(url, delegate:self)
end

def application(application, openURL:url, sourceApplication:sourceApplication, annotation:annotation)
  WXApi.handleOpenURL(url, delegate:self)
end

3. set up onResp in app_delegate.rb. this is when it comes back from wexin app

def onResp(resp)
  if resp.is_a? SendAuthResp
    # resp has *token* *lang* *country* *code*
    MotionWechat::API.instance.registerClient resp.code
    MotionWechat::API.instance.get_user_info do |info|
      # send *info* to server for authentication
    end
  end
end

TODO

  • delegate helpers, i.e. WXApi.handleOpenURL(url, delegate:self)
  • state & key validating in application(application, handleOpenURL:url)

Contributions

smartweb

Fork, please!