Exemplo n.º 1
0
 /**
  * 微信支付 WeixinJSBridge invoke 方式配置文件
  */
 public static function getPaymentConfig(Unifiedorder $unifiedorder, $asArray = false)
 {
     $bag = $unifiedorder->getBag();
     $res = $unifiedorder->getResponse();
     $config = new Bag();
     $config->set('appId', $bag->get('appid'));
     $config->set('timeStamp', time());
     $config->set('nonceStr', $res['nonce_str']);
     $config->set('package', 'prepay_id=' . $res['prepay_id']);
     $config->set('signType', 'MD5');
     $signGenerator = new SignGenerator($config);
     $signGenerator->onSortAfter(function ($that) use($unifiedorder) {
         $that->set('key', $unifiedorder->getKey());
     });
     $config->set('paySign', $signGenerator->getResult());
     $config->remove('key');
     return $asArray ? $config->all() : JSON::encode($config->all());
 }