Example #1
0
 /**
  * 构造方法
  */
 public function __construct(Wechat $wechat, array $options)
 {
     if (!$wechat->offsetExists('mchid')) {
         throw new \InvalidArgumentException('The required options "mch_id" are missing.');
     }
     if (!$wechat->offsetExists('mchkey')) {
         throw new \InvalidArgumentException('The required options "mch_key" are missing.');
     }
     $this->wechat = $wechat;
     parent::__construct($options);
 }
Example #2
0
 /**
  * 构造方法
  */
 public function __construct(Wechat $wechat, array $options)
 {
     if (!$wechat->offsetExists('mchid')) {
         throw new \InvalidArgumentException('The required options "mch_id" are missing.');
     }
     if (!$wechat->offsetExists('mchkey')) {
         throw new \InvalidArgumentException('The required options "mch_key" are missing.');
     }
     if (!$wechat->offsetExists('authenticate_cert')) {
         throw new \InvalidArgumentException('The required options "authenticate_cert" are missing.');
     }
     $defaults = array('wxappid' => $wechat['appid'], 'mch_id' => $wechat['mchid'], 'nonce_str' => uniqid(), 'client_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0');
     $validator = new OptionValidator();
     $validator->setDefined($this->required)->setRequired($this->required)->setDefaults($defaults);
     $validated = $validator->validate($options);
     $this->wechat = $wechat;
     $this->options = $validated;
 }
Example #3
0
 /**
  * 构造方法
  */
 public function __construct(Wechat $wechat, array $options)
 {
     if (!$wechat->offsetExists('mchid')) {
         throw new \InvalidArgumentException('The required options "mchid" are missing.');
     }
     if (!$wechat->offsetExists('mchkey')) {
         throw new \InvalidArgumentException('The required options "mchkey" are missing.');
     }
     $defaults = array('appid' => $wechat['appid'], 'mch_id' => $wechat['mchid'], 'time_stamp' => time(), 'nonce_str' => uniqid());
     $resolver = new OptionsResolver();
     $resolver->setDefined($this->required)->setRequired($this->required)->setDefaults($defaults);
     $options = $resolver->resolve($options);
     // 按 ASCII 码排序
     ksort($options);
     $signature = http_build_query($options);
     $signature = urldecode($signature);
     $signature = strtoupper(md5($signature . '&key=' . $wechat['mchkey']));
     $options['sign'] = $signature;
     $this->options = $options;
 }
Example #4
0
 /**
  * 构造方法
  */
 public function __construct(Wechat $wechat, array $options)
 {
     if (!$wechat->offsetExists('mchid')) {
         throw new \InvalidArgumentException('The required options "mch_id" are missing.');
     }
     if (!$wechat->offsetExists('mchkey')) {
         throw new \InvalidArgumentException('The required options "mch_key" are missing.');
     }
     $normalizer = function ($options, $value) {
         if ($value === 'JSAPI' && !isset($options['openid'])) {
             throw new \InvalidArgumentException('The required options "openid" are missing.');
         }
         return $value;
     };
     $defaults = array('appid' => $wechat['appid'], 'mch_id' => $wechat['mchid'], 'spbill_create_ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0', 'trade_type' => current($this->tradeType), 'nonce_str' => uniqid());
     $validator = new OptionValidator();
     $validator->setDefined($this->defined)->setRequired($this->required)->setAllowedValues('trade_type', $this->tradeType)->setNormalizer('trade_type', $normalizer)->setDefaults($defaults);
     $validated = $validator->validate($options);
     $this->wechat = $wechat;
     $this->options = $validated;
 }