微信公众平台里的 protected $APPSECRET = secret; //受理商ID,身份标识 protected $MCHID = '11111111';//商户id //商户支付密钥Key protected $KEY = '192006250b4c09247ec02edce69f6a2d'; //回调通知接口 protected $APPURL = 'https://smart.afei.com/receivesuc'; //交易类型 protected $TRADETYPE = 'JSAPI'; //商品类型信息 protected $BODY = 'wx/book'; //微信支付类的构造函数 function __construct($openid,$outTradeNo,$totalFee){ $this->openid = $openid; //用户唯一标识 $this->outTradeNo = $outTradeNo; //商品编号 $this->totalFee = $totalFee; //总价 } //微信支付类向外暴露的支付接口 public function pay(){ $result = $this->weixinapp(); return $result; } //对微信统一下单接口返回的支付相关数据进行处理 private function weixinapp(){ $unifiedorder=$this->unifiedorder(); $parameters=array( 'appId'=>$this->APPID,//小程序ID 'timeStamp'=>''.time().'',//时间戳 'nonceStr'=>$this->createNoncestr(),//随机串 'package'=>'prepay_id='.$unifiedorder['prepay_id'],//数据包 'signType'=>'MD5'//签名方式 ); $parameters['paySign']=$this->getSign($parameters); return $parameters; } /* *请求微信统一下单接口 */ private function unifiedorder(){ $parameters =