百度开发者中心吧 关注:6,940贴子:13,018
  • 0回复贴,共1

百度云推送 权限验证失败

只看楼主收藏回复

在使用百度云推送的接口出现权限验证失败,报错:{"request_id":23356184,"error_code":20265,"error_msg":"Authentication failed"}
代码都检查了无数遍了,都没有什么问题,有大神指点一下嘛
用c++实现的
void CenterSchedule::HandleTuisongSingleDevice(const std::string channel_id, const std::string account_id)
{
std::string url = GET_CONFIG_STRING("tuisong_single_url", "");
std::string api_key = GET_CONFIG_STRING("api_key", "");
std::string secret_key = GET_CONFIG_STRING("secret_key", "");
int cur_time = (int)time(0);
SimpleJsonObject object;
object["title"] = "hello";
object["description"] = "helloworld";
std::string result;
object.GetResult(result);
std::map<std::string, std::string> param_list;
param_list["apikey"] = api_key;
param_list["timestamp"] = Utility::FormateToString(cur_time);
param_list["expires"] = Utility::FormateToString((cur_time)+60*60*24);
param_list["device_type"] = "3";
param_list["channel_id"] = channel_id;
param_list["msg"] = result;
param_list["msg_type"] = "1";
std::string sign = ALittle::CommonHelp::TuisongSign(param_list, "POST", url, secret_key);
std::string param = "apikey=" + api_key
+ "&timestamp=" + Utility::FormateToString(cur_time)
+ "&expires=" + Utility::FormateToString((cur_time)+60*60*24)
+ "&device_type=3"
+ "&sign=" + sign
+ "&msg_type=1"
+ "&channel_id=" + channel_id
+ "&msg=" + result;
param = STRING_2_UTF8(HttpSystem::UrlEncode(param).c_str());
ALITTLE_INFO("param = " << param);
std::string add_header = "Content-Type: application/x-www-form-urlencoded;charset=utf-8\r\n";
add_header += "User-Agent: BCCS_SDK/3.0 (Darwin; Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64; x86_64) PHP/5.6.3 (Baidu Push Server SDK V3.0.0 and so on..) cli/Unknown ZEND/2.6.0\r\n";
std::function<void(bool, const std::string&, const std::string&)> func;
func = std::bind(HandleBaiduTuisongReuslt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
ALittle::HttpSystem::SendRequestPostJson(url, param, func, add_header);
}
//百度云推送的签名
std::string CommonHelp::TuisongSign(std::map<std::string, std::string> param_map, const std::string& http_method, const std::string& url, const std::string& secret_key)
{
std::vector<std::string> vector_list;
std::map<std::string, std::string>::iterator it, end = param_map.end();
for (it = param_map.begin(); it != end; ++it)
vector_list.push_back(it->first);
sort(vector_list.begin(), vector_list.end(), TuisongSignCmp);
std::string vector_string = http_method + url;
for(int i = 0; i < vector_list.size(); i++)
{
vector_string += vector_list[i] + "=" + param_map[vector_list[i]];
}
vector_string += secret_key;
ALITTLE_INFO("vector_string = " << vector_string);
ALITTLE_INFO("encode = "<<HttpSystem::UrlEncode(vector_string));
std::string sign_md5 = ScriptSystem::MD5(HttpSystem::UrlEncode(vector_string));
ALITTLE_INFO("sign = "<<sign_md5);
return sign_md5;
}


IP属地:浙江1楼2017-03-08 10:25回复