Exemple #1
0
 /**
  *
  * 转换短链接
  * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
  * 减小二维码数据量,提升扫描速度和精确度。
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayShortUrl $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public static 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(WxPayConfig::APPID);
     //公众账号ID
     $inputObj->SetMch_id(WxPayConfig::MCHID);
     //商户号
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     $inputObj->SetSign();
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = self::getMillisecond();
     //请求开始时间
     $response = self::postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::Init($response);
     self::reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }
Exemple #2
0
 /**
  * 
  * 转换短链接
  * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
  * 减小二维码数据量,提升扫描速度和精确度。
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayShortUrl $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public static function shorturl($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/tools/shorturl";
     $inputObj->SetAppid(APPID);
     //公众账号ID
     $inputObj->SetMch_id(MCHID);
     //商户号
     $inputObj->SetNonce_str(self::getNonceStr());
     //随机字符串
     $inputObj->SetSign();
     //签名
     $xml = $inputObj->ToXml();
     $startTimeStamp = self::getMillisecond();
     //请求开始时间
     $response = self::postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::Init($response);
     //self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
     return $result;
 }
Exemple #3
0
 /**
  * 生成静态NATIVE方式的微信订单第一步
  * @param array $options 参数数组
  * @return array
  */
 public function createStaticNativeOrderFirst($options)
 {
     $resArr = ['code' => 0];
     //设置静态链接
     $nativeLinkModel = new WxPayNativeLink($this->wx_config);
     //设置静态链接参数
     $nativeLinkModel->setParameter("product_id", $options['product_id']);
     //商品id
     //获取链接
     $product_url = $nativeLinkModel->getUrl();
     //使用短链接转换接口
     $shortUrlModel = new WxPayShortUrl($this->wx_config);
     //设置必填参数
     $shortUrlModel->setParameter("long_url", $product_url . "");
     //URL链接
     //获取短链接
     $resArr['data'] = ['code_url' => $shortUrlModel->getShortUrl()];
     return $resArr;
 }
Exemple #4
0
 /**
  *
  * 转换短链接
  * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
  * 减小二维码数据量,提升扫描速度和精确度。
  * appid、mchid、spbill_create_ip、nonce_str不需要填入
  * @param WxPayShortUrl $inputObj
  * @param int $timeOut
  * @throws WxPayException
  * @return 成功时返回,其他抛异常
  */
 public function shorturl($inputObj, $timeOut = 6)
 {
     $url = "https://api.mch.weixin.qq.com/tools/shorturl";
     //检测必填参数
     if (!$inputObj->isLongUrlSet()) {
         throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
     }
     $inputObj->setAppid($this->apiConfig->appid);
     //公众账号ID
     $inputObj->setMchId($this->apiConfig->mchid);
     //商户号
     $inputObj->setMchKey($this->apiConfig->mchkey);
     //商户密钥
     $inputObj->setNonceStr($this->getNonceStr());
     //随机字符串
     $inputObj->setSign();
     //签名
     $xml = $inputObj->toXml();
     $startTimeStamp = $this->getMillisecond();
     //请求开始时间
     $response = $this->postXmlCurl($xml, $url, false, $timeOut);
     $result = WxPayResults::init($response, $this->apiConfig->mchkey);
     $this->reportCostTime($url, $startTimeStamp, $result);
     //上报请求花费时间
     return $result;
 }