Ejemplo n.º 1
0
 /**
  * 转换短链接
  * @param string $url
  */
 public function shortUrl($url)
 {
     $input = new ShortUrl();
     $input->setLongUrl($url);
     $values = $this->api->shorturl($input);
     if ($values['return_code'] === 'FAIL') {
         throw new WxpayException($values['return_msg']);
     }
     return $values['short_url'];
 }
Ejemplo n.º 2
0
 /**
  *
  * 转换短链接
  * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
  * 减小二维码数据量,提升扫描速度和精确度。
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param ShortUrl $input
  * @param int $time_out
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public function shorturl($input, $time_out = 6)
 {
     $url = 'https://api.mch.weixin.qq.com/tools/shorturl';
     //检测必填参数
     if (!$input->isLongUrlSet()) {
         throw new WxPayException('需要转换的URL,签名用原串,传输需URL encode!');
     }
     $input->setAppid(Wxpay::getConfig('appid'));
     //公众账号ID
     $input->setMchId(Wxpay::getConfig('mchid'));
     //商户号
     $input->setSubMchId(Wxpay::getConfig('sub_mch_id'));
     //子商户号
     $input->setNonceStr($this->getNonceStr());
     //随机字符串
     $input->setSign();
     //签名
     $xml = $input->toXml();
     $start_time_stamp = $this->getMillisecond();
     //请求开始时间
     $response = $this->postXmlCurl($xml, $url, false, $time_out);
     $result = Results::Init($response);
     $this->reportCostTime($url, $start_time_stamp, $result);
     //上报请求花费时间
     return $result;
 }