一些配置问题及参数的获取就不在此做赘述,直接上代码
注:这里是支付完成后的模板消息在选择模板消息时注意类型(支付类型)
private function template(){
vendor('appalipay.AopSdk');// 加载类库
//组装相应参数
$user = '用户id';
$template = "模板id";
//按自己的模板去定义
$data = array('keyword1' => array('value'=>''),'keyword2' => array('value'=>''));
$form_id = '支付宝交易单号';
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = C('ALIPAY_APPID');
$aop->rsaPrivateKey = C('PRIVATE_KEY');
$aop->alipayrsaPublicKey= C('PUBLIC_KEY');
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$request = new \AlipayOpenAppMiniTemplatemessageSendRequest();
$bizcontent = json_encode([
'to_user_id'=>$user, //用户id
'form_id' => $form_id,
'user_template_id'=> $template, //模板id
'page'=> 'page/index/index',
'data'=> $data
]);
$request->setBizContent($bizcontent);
$result = $aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo '成功';
} else {
echo '失败';
}
} 