Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 美女被免费视频网站九色,久久国产网站,欧美性色黄大片a级毛片视频

          整合營銷服務商

          電腦端+手機端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          vue,h5頁面微信支付獲取code流程總結


          目中遇到一個需要微信獲取code支付,其中遇到很多問題,現(xiàn)在做一下總結。


          一、進入頁面獲取code:



          二、截取code:


          ?

          5網(wǎng)頁實現(xiàn)微信分享功能

          • 一,首先在公眾號管理后臺“公眾號設置”的“功能設置”里填寫JS接口安全域名,域名需要通過ICP備案,沒有備案域名可以用SAE、BAE等平臺。此外,自定義分享功能需要通過微信認證才能使用,沒有認證的可以跟關系好的朋友借用權限,在他的JS接口安全域名設置這里填上你的域名和共享同一個開發(fā)者ID。
          • 二,在需要調(diào)用JS接口的頁面引入微信JSSDK的JS文件 。這個文件在需要分享的頁面是必須要引用的,單獨特別重申一下,其他方面請閱讀官方文檔。
          
          <script type="text/javascript"
              src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
          <script type="text/javascript">
              /*
               * 注意:
               * 1. 所有的JS接口只能在公眾號綁定的域名下調(diào)用,公眾號開發(fā)者需要先登錄微信公眾平臺進入“公眾號設置”的“功能設置”里填寫“JS接口安全域名”。
               * 2. 如果發(fā)現(xiàn)在 Android 不能分享自定義內(nèi)容,請到官網(wǎng)下載最新的包覆蓋安裝,Android 自定義分享接口需升級至 6.0.2.58 版本及以上。
               * 3. 常見問題及完整 JS-SDK 文檔地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
               *
               * 開發(fā)中遇到問題詳見文檔“附錄5-常見錯誤及解決辦法”解決,如仍未能解決可通過以下渠道反饋:
               * 郵箱地址:weixin-open@qq.com
               * 郵件主題:【微信JS-SDK反饋】具體問題
               * 郵件內(nèi)容說明:用簡明的語言描述問題所在,并交代清楚遇到該問題的場景,可附上截屏圖片,微信團隊會盡快處理你的反饋。
               */
              $(function() {
                  var url = location.href.split('#')[0];
                  //alert(url);
          
                  $.ajax({
                      url : "wap_sign_signature.htm",
                      data : {
                          "url" : url
                      },
                      dataType : "json",
                      timeout : 5000,
                      error : function(XMLHttpRequest, textStatus, errorThrown) {
                          if (textStatus == "timeout") { // 請求超時
                          } else {
                          }
                      },
                      success : function(data, textStatus) {
          
                          if (textStatus == "success") { // 請求成功
                              //alert(data.nonceStr);
                              //alert(data.timestamp);
                              //alert(data.signature);  
                              wx.config({
                                  debug : false,
                                  appId : 'wxc4cf8e62667f92ea',
                                  timestamp : data.timestamp,
                                  nonceStr : data.nonceStr,
                                  signature : data.signature,
                                  jsApiList : [ 'onMenuShareAppMessage',
                                          'onMenuShareTimeline' ]
                              });
                          }
                      }
                  });
              });
          </script>
          
          <script type="text/javascript">
              /*
               * 注意:
               * 1. 所有的JS接口只能在公眾號綁定的域名下調(diào)用,公眾號開發(fā)者需要先登錄微信公眾平臺進入“公眾號設置”的“功能設置”里填寫“JS接口安全域名”。
               * 2. 如果發(fā)現(xiàn)在 Android 不能分享自定義內(nèi)容,請到官網(wǎng)下載最新的包覆蓋安裝,Android 自定義分享接口需升級至 6.0.2.58 版本及以上。
               * 3. 完整 JS-SDK 文檔地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
               *
               * 如有問題請通過以下渠道反饋:
               * 郵箱地址:weixin-open@qq.com
               * 郵件主題:【微信JS-SDK反饋】具體問題
               * 郵件內(nèi)容說明:用簡明的語言描述問題所在,并交代清楚遇到該問題的場景,可附上截屏圖片,微信團隊會盡快處理你的反饋。
               */
              // 發(fā)送給朋友并返回結果
              /* wx.checkJsApi({
                  jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline'], 
                  success: function(res) {
                      alert(reg);
                  }})
                      // 以鍵值對的形式返回,可用的api值true,不可用為false// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}});
                  }) */
          
              wx.ready(function() {
          
                  /*  wx.checkJsApi({
                      jsApiList: ['onMenuShareAppMessage'],
                      success:function(res){
                          alert(res.checkResult.chooseImage);
                      }
                  }) ; */
                  var title = "魔法媽咪學院入學啦!好媽咪快進來!";
                  var myurl = "http://diy-haier.highset.cn/index.jsp";
                  //分享給朋友
                  wx.onMenuShareAppMessage({
                      title : title, // 分享標題
                      desc : '海爾定制母嬰家電,讓你魔法加身,搞定養(yǎng)娃的大問題!', // 分享描述
                      link : myurl, // 分享鏈接
                      imgUrl : 'http://diy-haier.highset.cn/fx.jpg', // 分享圖標
                      type : 'link', // 分享類型,music、video或link,不填默認為link
                      success : function() {
                          // 用戶確認分享后執(zhí)行的回調(diào)函數(shù)
                      },
                      cancel : function() {
                          // 用戶取消分享后執(zhí)行的回調(diào)函數(shù)
                      }
                  });
          
                  wx.onMenuShareTimeline({
                      title : title, // 分享標題
                      link : myurl, // 分享鏈接
                      imgUrl : 'http://diy-haier.highset.cn/fx.jpg', // 分享圖標
                      success : function() {
                          // 用戶確認分享后執(zhí)行的回調(diào)函數(shù)
                      },
                      cancel : function() {
                          // 用戶取消分享后執(zhí)行的回調(diào)函數(shù)
                      }
                  });
          
              });
          
              wx.error(function(res) {
                  alert(res.errMsg);
              });
          </script>
          
          
          
          • 三、需要一個提供appid的token認證的服務,

          、開始開發(fā)

          https://developer.work.weixin.qq.com/document/path/91025

          企業(yè)微信提供了OAuth的掃碼登錄授權方式,可以讓企業(yè)的網(wǎng)站在瀏覽器內(nèi)打開時,引導成員使用企業(yè)微信掃碼登錄授權,從而獲取成員的身份信息,免去登錄的環(huán)節(jié)。(注:此授權方式需要用戶掃碼,不同于“網(wǎng)頁授權登錄”;僅企業(yè)內(nèi)可以使用此種授權方式,第三方服務商不支持使用。)在進行企業(yè)微信授權登錄之前,需要先在企業(yè)的管理端后臺創(chuàng)建一個具備“企業(yè)微信授權登錄”能力的應用。

          1.1 企業(yè)微信掃碼登陸接入流程


          1.2 開啟網(wǎng)頁授權登陸

          登錄 企業(yè)管理端后臺->進入需要開啟的自建應用->點擊 “企業(yè)微信授權登錄”,進入如下頁面



          然后點擊 "設置授權回調(diào)域",輸入回調(diào)域名,點擊“保存”。(域名:需要找運維做解析)

          要求配置的授權回調(diào)域,必須與訪問鏈接的域名完全一致,如下圖:


          1.3 構造獨立窗口登陸二維碼

          開發(fā)者需要構造如下的鏈接來獲取code參數(shù):

          https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=CORPID&agentid=AGENTID&redirect_uri=REDIRECT_URI&state=STATE

          參數(shù)說明:

          參數(shù)

          必須

          說明

          appid

          企業(yè)微信的CorpID,在企業(yè)微信管理端查看

          agentid

          授權方的網(wǎng)頁應用ID,在具體的網(wǎng)頁應用中查看

          redirect_uri

          重定向地址,需要進行UrlEncode

          state

          用于保持請求和回調(diào)的狀態(tài),授權請求后原樣帶回給企業(yè)。該參數(shù)可用于防止csrf攻擊(跨站請求偽造攻擊),建議企業(yè)帶上該參數(shù),可設置為簡單的隨機數(shù)加session進行校驗

          lang

          自定義語言,支持zh、en;lang為空則從Headers讀取Accept-Language,默認值為zh

          若提示“該鏈接無法訪問”,請檢查參數(shù)是否填寫錯誤,如redirect_uri的域名與網(wǎng)頁應用的可信域名不一致。

          若用戶不在agentid所指應用的可見范圍,掃碼時會提示無權限。

          返回說明:

          用戶允許授權后,將會重定向到redirect_uri的網(wǎng)址上,并且?guī)蟘ode和state參數(shù)

          redirect_uri?code=CODE&state=STATE

          若用戶禁止授權,則重定向后不會帶上code參數(shù),僅會帶上state參數(shù)

          redirect_uri?state=STATE

          示例:

          假定當前
          企業(yè)CorpID:wxCorpId
          開啟授權登錄的應用ID:1000000
          登錄跳轉鏈接:http://api.3dept.com
          state設置為:weblogin@gyoss9
          需要配置的授權回調(diào)域為:api.3dept.com
          根據(jù)URL規(guī)范,將上述參數(shù)分別進行UrlEncode,得到拼接的OAuth2鏈接為:
          https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=wxCorpId&agentid=1000000&redirect_uri=回調(diào)域名&state=web_login%40gyoss9

          1.4 構造內(nèi)嵌登陸二維碼

          在需要展示企業(yè)微信網(wǎng)頁登錄二維碼的網(wǎng)站引入如下JS文件(支持https):

          步驟一:引入JS文件 (vue框架的話,放在index.html文件中)

          <script src="https://rescdn.qqmail.com/node/ww/wwopenmng/js/sso/wwLogin-1.0.0.js" type="text/javascript"></script>

          版本:

          舊版:http://rescdn.qqmail.com/node/ww/wwopenmng/js/sso/wwLogin-1.0.0.js
          新版(20220415更新):http://wwcdn.weixin.qq.com/node/wework/wwopen/js/wwLogin-1.2.7.js

          步驟二:在需要使用微信登錄的地方實例JS對象(React同理)

          注意:從wwLogin-1.2.5.js開始需要使用new WwLogin進行實例化

          <template>
            <el-tabs v-model="activeName" @tab-click="handleClick" >
              <el-tab-pane label="賬戶密碼登錄" name="first" class="wechart-pane">
                <el-form-item prop="tenant">
                  <el-input
                    v-model="loginForm.tenant"
                    type="text"
                    auto-complete="off"
                    placeholder="租戶"
                  >
                    <i
                      slot="prefix"
                      class="el-input__icon el-icon-office-building"
                    ></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="username">
                  <el-input
                    v-model="loginForm.username"
                    icon="el-icon-user"
                    type="text"
                    auto-complete="off"
                    placeholder="賬號"
                  >
                    <i slot="prefix" class="el-input__icon el-icon-user"></i>
                  </el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input
                    v-model="loginForm.password"
                    icon="el-icon-unlock"
                    type="password"
                    auto-complete="off"
                    placeholder="密碼"
                    @keyup.enter.native="handleLogin"
                  >
                    <i slot="prefix" class="el-input__icon el-icon-unlock"></i>
                  </el-input>
                </el-form-item>
                <el-form-item>
                  <el-button
                    :loading="loading"
                    size="medium"
                    type="primary"
                    style="width: 100%"
                    @click.native.prevent="handleLogin"
                  >
                    登 錄
                  </el-button>
                </el-form-item>
              </el-tab-pane>
              <el-tab-pane label="掃碼登錄" name="second" class="wechart-pane" >
                <div id="wx_qrcode"></div>
              </el-tab-pane>
            </el-tabs>
          </template>

          腳本部分:定義全局變量wwLogin,方便后面銷毀

          handleClick(tab, event) {
            const that = this;
            if (tab){
              switch (tab.name) {
                case 'first':
                  if (that.wwLogin != null){
                    that.wwLogin.destroyed(); // 注意wwLogin為實例對象,無需登錄時,可手動銷毀實例
                  }
                  break;
                case 'second':
                  that.wwLogin = new WwLogin({
                    'id': 'wx_qrcode', //二維碼顯示區(qū)域div的id值
                    'appid': '企業(yè)微信后臺的corpid',
                    'agentid': '企業(yè)微信后臺的agentid',
                    'redirect_uri': '回調(diào)地址(必須為域名模式)', //http://localhost:53362/connect/token
                    'state': '',
                    'href': '',
                    'lang': 'zh',
                  })
                  break;
                default:break;
              }
            }
          },

          @@登陸順序:

          此處先介紹一下abpvnext登陸時訪問接口或者服務順序:

          1. 發(fā)現(xiàn)文檔配置

          http://localhost:53362/.well-known/openid-configuration

          訪問結果如下所示:

          {
              "issuer": "http://localhost:53362",
              "jwks_uri": "http://localhost:53362/.well-known/openid-configuration/jwks",
              "authorization_endpoint": "http://localhost:53362/connect/authorize",
              "token_endpoint": "http://localhost:53362/connect/token",
              "userinfo_endpoint": "http://localhost:53362/connect/userinfo",
              "end_session_endpoint": "http://localhost:53362/connect/endsession",
              "check_session_iframe": "http://localhost:53362/connect/checksession",
              "revocation_endpoint": "http://localhost:53362/connect/revocation",
              "introspection_endpoint": "http://localhost:53362/connect/introspect",
              "device_authorization_endpoint": "http://localhost:53362/connect/deviceauthorization",
              "frontchannel_logout_supported": true,
              "frontchannel_logout_session_supported": true,
              "backchannel_logout_supported": true,
              "backchannel_logout_session_supported": true,
              "scopes_supported": [
                  "openid",
                  "profile",
                  "email",
                  "address",
                  "phone",
                  "role",
                  "BaseService",
                  "InternalGateway",
                  "WebAppGateway",
                  "BusinessService",
                  "offline_access"
              ],
              "claims_supported": [
                  "sub",
                  "birthdate",
                  "family_name",
                  "gender",
                  "given_name",
                  "locale",
                  "middle_name",
                  "name",
                  "nickname",
                  "picture",
                  "preferred_username",
                  "profile",
                  "updated_at",
                  "website",
                  "zoneinfo",
                  "email",
                  "email_verified",
                  "address",
                  "phone_number",
                  "phone_number_verified",
                  "role"
              ],
              "grant_types_supported": [
                  "authorization_code",
                  "client_credentials",
                  "refresh_token",
                  "implicit",
                  "password",
                  "urn:ietf:params:oauth:grant-type:device_code"
              ],
              "response_types_supported": [
                  "code",
                  "token",
                  "id_token",
                  "id_token token",
                  "code id_token",
                  "code token",
                  "code id_token token"
              ],
              "response_modes_supported": [
                  "form_post",
                  "query",
                  "fragment"
              ],
              "token_endpoint_auth_methods_supported": [
                  "client_secret_basic",
                  "client_secret_post"
              ],
              "id_token_signing_alg_values_supported": [
                  "RS256"
              ],
              "subject_types_supported": [
                  "public"
              ],
              "code_challenge_methods_supported": [
                  "plain",
                  "S256"
              ],
              "request_parameter_supported": true
          }

          代碼方式獲取(Url可配置在appsettings.json或者nacos配置中心):

          var client = new HttpClient() ; 
          var disco = await client.GetDiscoveryDocumentAsync("http://localhost:53362/.well-known/openid-configuration"); 

          2. 獲取token的Url地址

          http://localhost:53362/connect/token

          3. 根據(jù)token獲取用戶信息地址

          http://localhost:53362/connect/userinfo

          4. vue-element-admin菜單權限是使用用戶角色來控制的,我們不需要role,通過接口:

          http://localhost:53362/api/abp/application-configuration

          返回結果中的auth.grantedPolicies字段,與對應的菜單路由綁定,就可以實現(xiàn)權限的控制。

          2、企業(yè)微信掃碼成功后回調(diào)/connect/token原理:

          通過查看IdentityServer4的源碼發(fā)現(xiàn),通過GrantType來區(qū)分不同的授權方式,除了常規(guī)的授權方式之外,在defaut條件中,有自定義授權生成token的方式(ProcessExtensionGrantRequestAsync),可以通過這種方式集成舊的業(yè)務系統(tǒng)驗證,比如,企業(yè)微信掃碼、小程序授權、短信登陸、微信登陸、釘釘?shù)顷?等等不同第三方進行集成。

          2.1自定義授權實現(xiàn)

          public class ExtensionGrantTypes
              {
                  //擴展授權名稱
                  public const string WeChatQrCodeGrantType = "WeChat";
              }
          
              public class WeChatQrCodeGrantValidator : IExtensionGrantValidator
              {
                  public string GrantType => ExtensionGrantTypes.WeChatQrCodeGrantType;
                  private readonly DateTime DateTime1970 = new DateTime(1970, 1, 1).ToLocalTime();
                  private readonly UserManager<Volo.Abp.Identity.IdentityUser> _userManager;
                  private readonly IJsonSerializer _jsonSerializer;
          
                  public WeChatQrCodeGrantValidator(
          UserManager<Volo.Abp.Identity.IdentityUser> userLoginManager,
          IJsonSerializer jsonSerializer)
                  {
                      _userManager = userLoginManager;
                      _jsonSerializer = jsonSerializer;
                  }
                  public async Task ValidateAsync(ExtensionGrantValidationContext context)
                  {
          
                      string code = context.Request.Raw.Get("Code");
                      if (string.IsNullOrEmpty(code))
                      {
                          context.Result = new GrantValidationResult(IdentityServer4.Models.TokenRequestErrors.InvalidGrant);
                      }
          
                      //下面第1、2可以封裝成接口或服務,參考下面3.1、3.2 部分,方便后期接入
          
                      //1、獲取企業(yè)微信訪問令牌access_token
                      string accessToken = "123123123123";
          
                      //2、獲取企業(yè)微信訪問用戶身份(企業(yè)微信號) UserId
                      string userId = "ZhangSan";
          
                      //3、根據(jù)企業(yè)微信用戶身份userId找到業(yè)務庫用戶表對比,找到真實的用戶信息
          
                      if (!string.IsNullOrEmpty(userId))
                      {
                          context.Result = await ServerValidate("", ""); //可以把UserId傳進去
                      }
                      else
                          context.Result = new GrantValidationResult(IdentityServer4.Models.TokenRequestErrors.InvalidGrant);
          
                  }
                          
          
                  /// <summary>
                  /// 服務器端驗證并輸出用戶信息,后續(xù)自動生成token
                  /// </summary>
                  /// <param name="loginProvider"></param>
                  /// <param name="providerKey"></param>
                  /// <returns></returns>
                  private async Task<GrantValidationResult> ServerValidate(string loginProvider, string providerKey)
                  {
                      var user = await _userManager.FindByLoginAsync(loginProvider, providerKey); //業(yè)務庫用戶
                      if (user == null)
                          return new GrantValidationResult(IdentityServer4.Models.TokenRequestErrors.InvalidGrant);
                      var principal = new ClaimsPrincipal();
                      List<ClaimsIdentity> claimsIdentity = new List<ClaimsIdentity>();
                      ClaimsIdentity identity = new ClaimsIdentity();
                      identity.AddClaim(new Claim("sub", user.Id.ToString()));
                      identity.AddClaim(new Claim("tenantid", user.TenantId.ToString())); //租戶Id
                      identity.AddClaim(new Claim("idp", "local"));
                      identity.AddClaim(new Claim("amr", loginProvider));
                      long authTime = (long)(DateTime.Now.ToLocalTime() - DateTime1970).TotalSeconds;
                      identity.AddClaim(new Claim("auth_time", authTime.ToString()));
                      claimsIdentity.Add(identity);
                      principal.AddIdentities(claimsIdentity);
                      return new GrantValidationResult(principal);
                  }
              }

          2.2 添加擴展方法(在實現(xiàn)AbpModel類中)

          public override void PreConfigureServices(ServiceConfigurationContext context)
          {
              context.Services.PreConfigure<IIdentityServerBuilder>(builder => { 
                  builder.AddExtensionGrantValidator<WeChatQrCodeGrantValidator>(); 
              });
          }

          2.3 在Domain項目中的identityServer 文件夾中的種子數(shù)據(jù)添加grantTypes(CreateClientAsync()下)

          await CreateClientAsync(
              name: "wechat-web",
              scopes: commonScopes.Union(new[] {
                   "IdentityService", "InternalGateway", "WebAppGateway", "BusinessService","WeChat"
              }),
              grantTypes: new[] { "WeChat" },
              //redirectUri: $"http://localhost:44307/authentication/login-callback",
              requireClientSecret: false
          );

          2.4 前三步執(zhí)行后,無需執(zhí)行Add-Migration/Update-Database命令,直接啟動服務,種子數(shù)據(jù)會自動入庫并配置好。

          2.5 訪問token

          http://localhost:53362/connect/token

          是不是發(fā)現(xiàn)這個鏈接熟悉,沒錯就是上面“@@登陸順序”部分,前端按之前賬號、密碼登陸方式調(diào)用即可,切換為下面的參數(shù),后續(xù)同@@登陸順序部分一致。


          3、企業(yè)微信獲取token和用戶賬號

          3.1 獲取訪問令牌access_token

          請求地址:

          https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET
          #corpid、corpsecret換為自己的corpid、應用secret

          返回結果:

          {"access_token":"sdfadsf","expires_in":15,"errcode":0,"errmsg":"ok"}

          3.2 獲取訪問用戶身份(企業(yè)微信號)

          請求地址:

          https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE

          返回結果:

          {"UserId":"WangWu","DeviceId":"","errcode":0,"errmsg":"ok"}

          3.3獲取UserId與本地庫User表比對,找到真實的用戶信息

          獲取用戶信息(賬號、密碼)去取token(類似用戶賬號、密碼登錄的token)


          (此處已添加書籍卡片,請到客戶端查看)
          (此處已添加紀錄片卡片,請到客戶端查看)

          主站蜘蛛池模板: 亚洲夜夜欢A∨一区二区三区 | 波多野结衣一区二区三区88| 国产乱码一区二区三区| 中文乱码精品一区二区三区| 精品国产一区二区三区久久久狼 | 精品在线一区二区| 无码人妻一区二区三区一| 中文字幕一区二区免费| 高清在线一区二区| 国产成人久久一区二区不卡三区| 午夜天堂一区人妻| 亚洲一区二区三区乱码A| 无码国产精品一区二区高潮| 91精品福利一区二区| 日韩精品国产一区| 波多野结衣一区二区三区高清av| 国产日韩精品一区二区三区| 在线观看中文字幕一区| 精品一区二区三区在线观看l| 少妇无码一区二区二三区| 一区二区三区在线|欧| 精品一区二区三区色花堂| 国产日韩AV免费无码一区二区三区 | 极品人妻少妇一区二区三区| 无码人妻一区二区三区免费看 | 性色AV一区二区三区天美传媒| 亚洲一区二区三区电影| 色妞色视频一区二区三区四区| 性色A码一区二区三区天美传媒| 日韩一区二区电影| 日本内射精品一区二区视频| 麻豆果冻传媒2021精品传媒一区下载| 亚洲国产视频一区| 国产乱码精品一区二区三区 | 国产亚洲日韩一区二区三区 | 一区二区三区视频在线观看| 亚洲综合一区二区| 日韩AV片无码一区二区不卡| 激情综合丝袜美女一区二区| 三上悠亚精品一区二区久久| 97久久精品一区二区三区|