/** * 获取配置 */ public function getConfig($asArray = false) { $options = array('appid' => $this->accessToken->getAppid(), 'url' => Util::getCurrentUrl(), 'timestamp' => Util::getTimestamp(), 'noncestr' => Util::getRandomString(), 'accesstoken' => $this->accessToken['access_token']); // 按 ASCII 码排序 ksort($options); $signature = http_build_query($options); $signature = urldecode($signature); $signature = sha1($signature); $config = array('appId' => $options['appid'], 'scope' => 'jsapi_address', 'signType' => 'sha1', 'addrSign' => $signature, 'timeStamp' => $options['timestamp'], 'nonceStr' => $options['noncestr']); return $asArray ? $config : Serializer::jsonEncode($config); }
/** * 获取配置文件 */ public function getConfig($asArray = false) { $ticket = new Ticket($this->accessToken); if ($this->cache) { $ticket->setCache($this->cache); } $options = array('jsapi_ticket' => $ticket->getTicketString(), 'timestamp' => Util::getTimestamp(), 'url' => Util::getCurrentUrl(), 'noncestr' => Util::getRandomString()); ksort($options); $signature = sha1(urldecode(http_build_query($options))); $configure = array('appId' => $this->accessToken['appid'], 'nonceStr' => $options['noncestr'], 'timestamp' => $options['timestamp'], 'signature' => $signature, 'jsApiList' => $this->api, 'debug' => (bool) $this->debug); return $asArray ? $configure : Serializer::jsonEncode($configure); }
/** * 构造方法 */ public function __construct(Unifiedorder $unifiedorder, array $defaults = array()) { $res = $unifiedorder->getResponse(); $key = $unifiedorder->getKey(); $config = array('appId' => $unifiedorder['appid'], 'timeStamp' => Util::getTimestamp(), 'nonceStr' => Util::getRandomString(), 'package' => 'prepay_id=' . $res['prepay_id'], 'signType' => 'MD5'); // 如果需要指定以上参数,可以通过 $defaults 变量传入 $options = array_replace($config, $defaults); ksort($options); $queryString = urldecode(http_build_query($options)); $paySign = strtoupper(md5($queryString . '&key=' . $key)); $options['paySign'] = $paySign; parent::__construct($options); }
/** * 获取支付链接 */ public function getPayurl($productId, array $defaults = array()) { $defaultOptions = array('appid' => $this['appid'], 'mch_id' => $this['mch_id'], 'time_stamp' => Util::getTimestamp(), 'nonce_str' => Util::getRandomString()); $options = array_replace($defaultOptions, $defaults); $options['product_id'] = $productId; // 按 ASCII 码排序 ksort($options); $signature = urldecode(http_build_query($options)); $signature = strtoupper(md5($signature . '&key=' . $this->key)); $options['sign'] = $signature; $query = http_build_query($options); return self::PAYMENT_URL . '?' . urlencode($query); }