
Security News
Oxlint Introduces Type-Aware Linting Preview
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Wechat SNS library is a low level library for Wechat SNS APIs. 微信社交库是一个调用微信社交API的低层库。
Check out the Road Map to find out what's the next. Check out the Change Log to find out what's new.
Add this line to your application's Gemfile:
gem 'wechat-sns'
And then execute:
$ bundle
Or install it yourself as:
$ gem install wechat-sns
Generate an Authorize URL and Redirect 第一步:用户同意授权,获取code
redirect_to Wechat::SNS::AuthorizeLink.create(Rails.application.secrets.wechat_app_id, 'http://product.company.com/promotion/page.html')
Get Access Token per Code 第二步:通过code换取网页授权access_token
response = Wechat::SNS::AccessToken.create Rails.application.secrets.wechat_app_id, Rails.application.secrets.wechat_app_secret, params[:code]
if response.present?
access_token = response['access_token']
expires_in = response['expires_in']
refresh_token = response['refresh_token']
open_id = response['openid']
scope = response['scope']
union_id = response['unionid']
end
Refresh Access Token 第三步:刷新access_token(如果需要)
response = Wechat::SNS::AccessToken.update Rails.application.secrets.wechat_app_id, refresh_token
if response.present?
access_token = response['access_token']
expires_in = response['expires_in']
refresh_token = response['refresh_token']
open_id = response['openid']
scope = response['scope']
end
Get User Profile per Access Token 第四步:拉取用户信息(需scope为 snsapi_userinfo)
response = Wechat::SNS::UserProfile.load access_token, open_id
if response.present? && response['errcode'].blank?
open_id = response['openid']
nick_name = response['nickname']
sex = response['sex']
city = response['city']
province = response['province']
country = response['country']
head_image_url = response['headimgurl']
privilege = response['privilege']
union_id = response['unionid']
end
Validate Access Token 附:检验授权凭证(access_token)是否有效
response = Wechat::SNS::AccessToken.load access_token, open_id
if response.present? && 0==response['errcode']
# valid, do something more with the access_token
Wechat::SNS::UserProfile.load access_token, open_id
else
# invalid, the access_token should be updated
Wechat::SNS::AccessToken.update Rails.application.secrets.wechat_app_id, refresh_token
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/topbitdu/wechat-sns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that wechat-sns demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.