如下图所示,我在调试工具里面调用是完全可以成功的,但是使用服务器的代码调用就一直报41037的错误。
请问是我的代码哪里有问题吗。。。。
$curl = curl_init();
//获取 $ACCESS_TOKEN
// 请求置换 $ACCESS_TOKEN
$access_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=".$corpid."&corpsecret=".$corpsecret;
$ACCESS_TOKEN_DATA = json_decode(send_get($access_url),TRUE);
$ACCESS_TOKEN = $ACCESS_TOKEN_DATA["access_token"];
// printf($ACCESS_TOKEN);
// 请求{联系我}
$telme_url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_contact_way?access_token=".$ACCESS_TOKEN;
$telme_data = Array (
"access_token" => $ACCESS_TOKEN,
"type" => '1',
"scene" => '2',
"user" => 'ZhangYu',
);
$TELME_DATA = json_decode(send_post($telme_url,$telme_data),TRUE);
$TELME = $TELME_DATA["access_token"];
var_dump($TELME_DATA);
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
function send_post($url, $post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
function send_get ($url) {
$s = file_get_contents($url);
return $s;
}
?>
您好,错误码是提示联系方式为空,看贴的代码这里是加了引号,加了引号的话就是字符了,不加表示数字,按照文档的来吧
另外我使用本地的接口测试工具填写的参数,调用结果也是一样的。
hint: [1597227286_98_a50f04d4afffc254d9b7bb5bb47647e5],这个是18:14调用的记录,如果您方便的话,能帮忙查看一下吗?
$telme_data = Array (
"access_token" => $ACCESS_TOKEN,
"type" => 1,
"scene" => 2,
"user" => 'ZhangYu',
);
$telme_data = Array (
"access_token" => $ACCESS_TOKEN,
"type" => 1,
"scene" => 2,
"user" => ["ZhangYu"],
);
/www/wwwroot/weiqing.jianzhibox.com/nologin.php:48:
array (size=5)
'access_token' => string 'qb_j3zMvT9l59VVUkyDczb27iy-0iOk8UMjWBpgil6MawHbJB8TJqmUQtqgjpkWVVp_scqneg-_A5PEaTunVtq81HmWg4mUO6TKjyFAcMTA_lTnqDN_XVDX5kt4NdGjQBBjiX6nWPhswxeTfrsuWpwGmzvaF7jobjAhwC35S3WcYgepbRVv4picF31L7mD1VbgwIbg-8DKaqf_9-WWI6_A' (length=214)
'type' => int 1
'scene' => int 2
'user' =>
array (size=1)
0 => string 'ZhangYu' (length=7)
'party' =>
array (size=1)
0 => int 1
/www/wwwroot/weiqing.jianzhibox.com/nologin.php:30:
array (size=2)
'errcode' => int 41037
'errmsg' => string 'Warning: wrong json format. missing contact way type, hint: [1597283618_98_847016e7041f7143cf698a0f57cf6e0a], from ip: 192.144.212.38, more info at https://open.work.weixin.qq.com/devtool/query?e=41037' (length=201)
'party' =>
我也遇到这问题,把数组转成Json格式就正常了,文档坑人啊,各种尝试
请问一下这个问题后来如何解决的,遇到同样的问题