function wx_sendtext($openid,$text,$appId,$appSecret) {

  $access_token = get_access_token($appId,$appSecret);
  $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
  $data_string = '{"touser":"'.$openid.'","msgtype":"text","text":{"content":"'.$text.'"}}';

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8','Content-Length: ' . strlen($data_string)));
  ob_start();
  curl_exec($ch);
  $return_content = ob_get_contents();
  ob_end_clean();

  $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

  return array($return_code, $return_content);
}

发送内容到指定用户,直接输入内容和对应openid

 

希望各位大神能帮我的代码继续优化