微信小程序模板消息

1 先去小程序平台,选择现有模板或申请自定义模板,会有一个模板编号

public function temMsg(Request $request){
  //1订单状态2订单内容3订单编号4联系人姓名
  $data = $request->param();
  $field = Db::name('order')->where('id',$data['zjid'])->find();

  //$n_type = $field['name_type'];
  $key1 = $field['nickname'] ?? '匿名';
  $key2 = $field['order_num'];
  $key3 = str_replace(',',"\n",$field['content']);
  //$key4 = $field["avatar"];
  $formid = $data['formid'];
  $temid = '';//模板消息编号

  $openid = Db::name('member')->where('id',$data['uid'])->value('wxopenid');

  $access_token = $this->returnAssKey();
  $url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='.$access_token;
  $data = array(
    "touser"=>$openid,
    "template_id"=>$temid,
    // "page"=>$page,
    "form_id"=>$formid,
    "data"=>array(
    "keyword1"=>array(
    "value"=>$key1,
    "color"=>"#173177"
    ),
    "keyword2"=>array(
      "value"=>$key2,
      "color"=>"#173177"
    ),
    "keyword3"=>array(
      "value"=>$key3,
      "color"=>"#173177"
    )
  ),
  // "emphasis_keyword"=>"keyword1.DATA",//需要进行加大的消息
);
  $res = $this->postCurl($url,$data,'json');//将data数组转换为json数据

  return $res ? json(['status'=>1,'data'=>$res,'msg'=>'成功']) : json(['status'=>0,'data'=>'','msg'=>'失败']);
}

猜你喜欢

转载自www.cnblogs.com/qczy/p/10942278.html