Externalcontact.php 845 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace wx\work;
  3. class Externalcontact extends Work
  4. {
  5. public function __construct($corpid, $corpsecret)
  6. {
  7. parent::__construct($corpid, $corpsecret);
  8. }
  9. /**
  10. * 外部联系人openid转换
  11. * @param external_userid string 外部联系人userid
  12. * @return string openid
  13. */
  14. public function convertToOpenid($external_userid)
  15. {
  16. $url = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/convert_to_openid?access_token='.$this->accessToken;
  17. $res = $this->curl($url, json_encode(['external_userid'=>$external_userid]));
  18. $res = json_decode($res, true);
  19. if (isset($res['errcode']) && $res['errcode'] != 0) {
  20. trace('外部联系人openid转换失败:'.$res['errmsg']);
  21. return null;
  22. }
  23. return $res['openid'];
  24. }
  25. }