【发布时间】:2014-01-06 13:12:00
【问题描述】:
这个网站试图解释这个过程:http://admin.wechat.com/wiki/index.php?title=Access_token
问题是他们没有告诉你从哪里得到AppID或者秘密是什么。有其他人成功与微信通信吗?
【问题讨论】:
标签: api access-token wechat
这个网站试图解释这个过程:http://admin.wechat.com/wiki/index.php?title=Access_token
问题是他们没有告诉你从哪里得到AppID或者秘密是什么。有其他人成功与微信通信吗?
【问题讨论】:
标签: api access-token wechat
基本上我们@微信有两种类型的帐户,订阅和服务。订阅帐户仅允许您访问消息 API,该 API 允许接收消息和自动回复,并允许您每天向用户广播一次。订阅帐户也在订阅下的联系人中的一个类别中分组。
服务帐户会为您提供一个 APP ID 和 APP SECRET,它允许您生成一个访问令牌,除了消息 API 之外,几乎所有其他 API 都需要该令牌。服务帐户显示在用户的联系人列表中,位于所有其他正常联系人之间的主要聊天下方。您只能在服务帐户上每月向每个用户广播一次。
如果你有服务账号,你会从 admin.wechat.com -> 登录 -> 功能 -> 高级 -> 开发者模式 -> 在你的令牌下你会看到 APP ID 和 APP SECRET应用秘密
要查看您拥有的帐户类型,请访问 admin.wechat.com -> 登录,然后查看您的帐户名称旁边的屏幕右上角,您会看到您的帐户名称,在上面会显示订阅帐户或服务帐户。
如果您想测试所有 API,我建议您进入开发人员沙盒环境,在该环境中您可以完全访问所有 API:How does link with href for Line and Wechat?
请注意,您的号码需要采用国际格式,因此 072 111 2233 您必须输入 +27721112233
【讨论】:
【讨论】:
您可以前往http://dev.wechat.com/注册开发者账号。
注册后,您将通过注册邮箱获得您的 App ID 和 AppKey。
然后,您可以前往http://admin.wechat.com/wiki/index.php?title=Main_Page获取更多信息。
【讨论】:
我在github上写了一段代码sn-p,解释了整个过程。该代码适用于 django,但可以与任何 python 框架一起使用
这是一个sn-p
import xml.etree.ElementTree as ET
from wechat.views import WeChatView
MyCustomView(WeChatView):
token = "ad4sf65weG7Db6ddWE"
on_message(self, message):
root = ET.fromstring(message)
from = root[1].text
message_type = root[3].text
content = root[4].text
print('from: {}'.format(from))
print('message type: {}'.format(message_type))
print('content: {}'.format(content))
【讨论】:
这是我的代码,也许你可以试试。
//Getting access_token from customize menus
static function get_access_token($appid,$secret){
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
$json=http_request_json($url);//here cannot use file_get_contents
$data=json_decode($json,true);
if($data['access_token']){
return $data['access_token'];
}else{
return "Error occurred while geting the access_token";
}
}
//Though URL request is https',cannot use file_get_contents.Using CURL while asking the JSON data
function http_request_json($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
【讨论】: