blsm-mp-wx 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/blsm-mp-wx/model/vd_wx_user.rb +7 -0
- data/lib/blsm-mp-wx/version.rb +1 -1
- data/lib/blsm-mp-wx.rb +52 -0
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1c73f477410ef96688ed160391f917d9b8d2c256
         | 
| 4 | 
            +
              data.tar.gz: 003d583687cd0d1ea87cb3f8e22dfed170a41187
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8b7084c4133c7303944afa4972599f476ae2305d8dc8033b8b7c52ef4568cb0e8eb915a80795d0e11977832b4e5be433a1327d7731fbbc68ef87364d6eacd9fc
         | 
| 7 | 
            +
              data.tar.gz: 44f3b74eabfa55cfb87f0084711fd4307e660430d0505cbd6c18b8cfa94f9b06233adb12d1766d5915181474d44f86f42cddea910f65b74f8819348f2b0c339d
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/blsm-mp-wx/version.rb
    CHANGED
    
    
    
        data/lib/blsm-mp-wx.rb
    CHANGED
    
    | @@ -11,6 +11,7 @@ require 'blsm-mp-wx/version' | |
| 11 11 | 
             
            require 'blsm-mp-wx/model/active_record'
         | 
| 12 12 | 
             
            require 'blsm-mp-wx/model/vd_mp_wx'
         | 
| 13 13 | 
             
            require 'blsm-mp-wx/model/vd_mp_msg'
         | 
| 14 | 
            +
            require 'blsm-mp-wx/model/vd_wx_user'
         | 
| 14 15 | 
             
            require 'json'
         | 
| 15 16 | 
             
            require 'faraday'
         | 
| 16 17 |  | 
| @@ -350,6 +351,57 @@ module BlsmMpWx | |
| 350 351 | 
             
                  returned_openids
         | 
| 351 352 | 
             
                end
         | 
| 352 353 |  | 
| 354 | 
            +
                #sns登录获取用户信息
         | 
| 355 | 
            +
                def sns_login_userinfo(code)
         | 
| 356 | 
            +
                  app_id = 'wx143306afc47c63a6'
         | 
| 357 | 
            +
                  app = VdMpWx.where(app_id: app_id).first
         | 
| 358 | 
            +
             | 
| 359 | 
            +
                  conn = Faraday.new(:url => 'https://api.weixin.qq.com')
         | 
| 360 | 
            +
                  response = conn.post do |req|
         | 
| 361 | 
            +
                    req.url '/sns/oauth2/access_token'
         | 
| 362 | 
            +
                    req.headers['Content-Type'] = 'application/xml'
         | 
| 363 | 
            +
                    req.params[:appid] = app_id
         | 
| 364 | 
            +
                    req.params[:secret] =app.app_secret
         | 
| 365 | 
            +
                    req.params[:code] = code
         | 
| 366 | 
            +
                    req.params[:grant_type] = 'authorization_code'
         | 
| 367 | 
            +
                  end
         | 
| 368 | 
            +
             | 
| 369 | 
            +
                  if response.body.encoding != 'UTF-8'
         | 
| 370 | 
            +
                    response_body = response.body.force_encoding('UTF-8')
         | 
| 371 | 
            +
                  else
         | 
| 372 | 
            +
                    response_body = response.body
         | 
| 373 | 
            +
                  end
         | 
| 374 | 
            +
             | 
| 375 | 
            +
                  res = parse_json(response_body)
         | 
| 376 | 
            +
             | 
| 377 | 
            +
             | 
| 378 | 
            +
                  conn = Faraday.new(:url => 'https://api.weixin.qq.com')
         | 
| 379 | 
            +
                  response = conn.post do |req|
         | 
| 380 | 
            +
                    req.url '/sns/userinfo'
         | 
| 381 | 
            +
                    req.headers['Content-Type'] = 'application/xml'
         | 
| 382 | 
            +
                    req.params[:access_token] = res['access_token']
         | 
| 383 | 
            +
                    req.params[:openid] = res['openid']
         | 
| 384 | 
            +
                  end
         | 
| 385 | 
            +
                  if response.body.encoding != 'UTF-8'
         | 
| 386 | 
            +
                    response_body = response.body.force_encoding('UTF-8')
         | 
| 387 | 
            +
                  else
         | 
| 388 | 
            +
                    response_body = response.body
         | 
| 389 | 
            +
                  end
         | 
| 390 | 
            +
             | 
| 391 | 
            +
                  res = parse_json(response_body)
         | 
| 392 | 
            +
                  VdWxUser.find_or_create_by({app_id: app_id, openid: res['openid']}) do |u|
         | 
| 393 | 
            +
                    u.update_attributes({nickname: res['nickname'],
         | 
| 394 | 
            +
                                         sex: res['sex'],
         | 
| 395 | 
            +
                                         unionid: res['unionid'],
         | 
| 396 | 
            +
                                         language: res['language'],
         | 
| 397 | 
            +
                                         city: res['city'],
         | 
| 398 | 
            +
                                         province: res['province'],
         | 
| 399 | 
            +
                                         country: res['country'],
         | 
| 400 | 
            +
                                         headimgurl: res['headimgurl'],
         | 
| 401 | 
            +
                                        })
         | 
| 402 | 
            +
                  end
         | 
| 403 | 
            +
                end
         | 
| 404 | 
            +
             | 
| 353 405 | 
             
                private
         | 
| 354 406 | 
             
                #解析json类型的数据,并将最后的数据转为hash或array
         | 
| 355 407 | 
             
                # +json_data_str+ 要转换的json数据
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: blsm-mp-wx
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - saxer
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-01-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         | 
| @@ -170,6 +170,7 @@ files: | |
| 170 170 | 
             
            - lib/blsm-mp-wx/model/active_record.rb
         | 
| 171 171 | 
             
            - lib/blsm-mp-wx/model/vd_mp_msg.rb
         | 
| 172 172 | 
             
            - lib/blsm-mp-wx/model/vd_mp_wx.rb
         | 
| 173 | 
            +
            - lib/blsm-mp-wx/model/vd_wx_user.rb
         | 
| 173 174 | 
             
            - lib/blsm-mp-wx/version.rb
         | 
| 174 175 | 
             
            homepage: https://bitbucket.org/Xiaopuzhu/blsm-mp-wx/
         | 
| 175 176 | 
             
            licenses:
         | 
| @@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 192 193 | 
             
                  version: '0'
         | 
| 193 194 | 
             
            requirements: []
         | 
| 194 195 | 
             
            rubyforge_project: 
         | 
| 195 | 
            -
            rubygems_version: 2.4. | 
| 196 | 
            +
            rubygems_version: 2.4.3
         | 
| 196 197 | 
             
            signing_key: 
         | 
| 197 198 | 
             
            specification_version: 4
         | 
| 198 199 | 
             
            summary: "首趣微店微信公众号基本模块"
         |