-请教,微信小程序客服 $postStr =file_get_contents(“php://input”); 获取不到文件, 消息推送已经启用,如果openid填写好推正常,人工 客服也正常,是什么原因,谢谢!
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr =file_get_contents(“php://input”);
if (empty($postStr))
{
echo ‘$ivar1’ . " 为空或为 0。" . PHP_EOL;
}
else
{
echo ‘$ivar1’ . " 不为空或不为 0。" . PHP_EOL;
}
print_r($postStr);
//extract post data
if (!empty($postStr)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, ‘SimpleXMLElement’, LIBXML_NOCDATA);
$fromUsername =trim($postObj->FromUserName);
echo $postObj;
$toUsername = $postObj->ToUserName;
// $keyword = trim($postObj->Content);
//$time = time();
$appid =“wx778804e73c086080”;
$secret=“2b93a9c0916d3f1ce73b5e5be5216f2c”;
$gettoken=“https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}”;
$result=$this->httpGet($gettoken);
$arr=json_decode($result,true);
$token=$arr[“access_token”];
//var_dump($result);
$postmsg=“https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=”.$token;
$textTpl=’{“touser”:’.$fromUsername.’,“msgtype”:“text”,“text”:{“content”: “Hello World你好世界”}}’;
$resultStr=$this->posturl($postmsg,$textTpl);
echo $resultStr;