wechat.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. # wechat基本配置
  3. $config['type'] = 5;
  4. # 基本的component token
  5. $config['token'] = array
  6. (
  7. 'name' => '获取第三方平台的token',
  8. 'method' => 'post',
  9. 'json' => true,
  10. 'url' => 'https://api.weixin.qq.com/cgi-bin/component/api_component_token?',
  11. 'param' => array
  12. (
  13. 'component_appid' => 'appid',
  14. 'component_appsecret' => 'secret',
  15. 'component_verify_ticket' => 'ticket',
  16. ),
  17. //针对一些返回的名称,做转换
  18. 'response' => array
  19. (
  20. 'component_access_token' => 'token',
  21. //'expires_in' => 'expires_in',
  22. ),
  23. );
  24. # oauth token
  25. $config['oauth'] = array
  26. (
  27. //第一步,请求code
  28. 'code' => array
  29. (
  30. 'name' => '获取oauth code',
  31. 'method' => 'post',
  32. 'json' => true,
  33. 'url' => 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?',
  34. 'param' => array
  35. (
  36. 'component_access_token' => 'token',
  37. 'component_appid' => 'appid',
  38. ),
  39. 'response' => array
  40. (
  41. 'pre_auth_code' => 'oauth.code',
  42. ),
  43. ),
  44. //第二步,拼装redirect,进行授权登录
  45. 'login' => array
  46. (
  47. 'name' => '获取oauth login',
  48. 'method' => 'get',
  49. 'json' => false,
  50. 'url' => 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?',
  51. 'param' => array
  52. (
  53. 'component_appid' => 'appid',
  54. 'pre_auth_code' => 'code',
  55. 'redirect_uri' => 'redirect',
  56. 'auth_type' => '3',
  57. ),
  58. ),
  59. //第三步,获取到token
  60. 'oauth' => array
  61. (
  62. 'name' => '获取oauth token',
  63. 'method' => 'post',
  64. 'json' => true,
  65. 'url' => 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?',
  66. 'param' => array
  67. (
  68. 'component_access_token' => 'token',
  69. 'component_appid' => 'appid',
  70. 'authorization_code' => 'auth_code',
  71. ),
  72. 'response' => array
  73. (
  74. 'authorization_info.authorizer_appid' => 'openid',
  75. 'authorization_info.authorizer_appid.key' => 'unionid',
  76. 'authorization_info.authorizer_access_token' => 'oauth.oauth',
  77. 'authorization_info.authorizer_refresh_token' => 'refresh',
  78. 'authorization_info.expires_in' => 'expires_in',
  79. 'authorization_info.func_info' => 'callback.component/auth.saveOauthInfo',//定义回调
  80. ),
  81. ),
  82. //第四步,根据refresh获取到token
  83. 'refresh' => array
  84. (
  85. 'name' => '根据refresh获取oauth token',
  86. 'method' => 'post',
  87. 'json' => true,
  88. 'url' => 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?',
  89. 'param' => array
  90. (
  91. 'component_access_token' => 'token',
  92. 'component_appid' => 'appid',
  93. 'authorizer_appid' => 'openid',
  94. 'authorizer_refresh_token' => 'refresh',
  95. ),
  96. 'response' => array
  97. (
  98. 'authorizer_access_token' => 'oauth.refresh',
  99. 'authorizer_refresh_token' => 'refresh',
  100. ),
  101. ),
  102. );
  103. # 获取用户信息
  104. $config['user'] = array
  105. (
  106. 'name' => '获取用户信息',
  107. 'method' => 'post',
  108. 'json' => true,
  109. 'url' => 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?',
  110. 'param' => array
  111. (
  112. 'component_access_token' => 'token',
  113. 'component_appid' => 'appid',
  114. 'authorizer_appid' => 'openid',
  115. ),
  116. );
  117. $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'component' . DIRECTORY_SEPARATOR;
  118. # 载入小程序接口配置
  119. $config += include($path . 'applet.php');
  120. return $config;