Example #1
0
 /**
  *
  * 构造获取open和access_toke的url地址
  * @param string $code,微信跳转带回的code
  *
  * @return string 请求的url
  */
 private function __CreateOauthUrlForOpenid($code)
 {
     $urlObj["appid"] = $this->config->getAppId();
     $urlObj["secret"] = $this->config->getAppsecret();
     $urlObj["code"] = $code;
     $urlObj["grant_type"] = "authorization_code";
     $bizString = $this->ToUrlParams($urlObj);
     return "https://api.weixin.qq.com/sns/oauth2/access_token?" . $bizString;
 }
Example #2
0
 /**
  *
  * 转换短链接
  * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
  * 减小二维码数据量,提升扫描速度和精确度。
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayShortUrl $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return mixed 成功时返回,其他抛异常
  */
 public function shorturl($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/tools/shorturl";
     //检测必填参数
     if (!$inputObj->IsLong_urlSet()) {
         throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
     }
     $inputObj->SetAppid($this->config->getAppId());
     //公众账号ID
     $inputObj->SetMch_id($this->config->getMchId());
     //商户号
     $inputObj->SetNonce_str($this->getNonceStr());
     //随机字符串
     $inputObj->SetSign();
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = $this->getMillisecond();
     //请求开始时间
     $response = $this->postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::Init($response);
     $this->reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }