parent
13576ca477
commit
76cfa83666
@ -1 +1 @@
|
||||
{"access_token":"ONE7uqb5MhyuYiOtMkzUMPJs8krCiQeBjWek_Q9glYtfCH-kkQKzv84dgxUv5VLBnb5zdKajWDyHqocvu71UwlVuVFhsXs9MwbVdCu1i4l2L5vKCkhNE5GuyO6WisXfvKOUfAEAYCI","expires_in":7200,"got_token_at":1460441290}
|
||||
{"access_token":"q51KZUeA6_-CCCH-Buy1mxFmRjcrCViHgk2mHHHqEDbjuA_pgCM1IyW1DASYvpzyB06xHiarujo3rz1Ucq3GRoXdgQ7hAoFCzkL_q3Z5vczLjwAjowAVwmulYE-cAij8ATUfADAWPQ","expires_in":7200,"got_token_at":1460601163}
|
@ -0,0 +1,113 @@
|
||||
class WechatService
|
||||
|
||||
def template_data(openid, template_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
||||
data = {
|
||||
touser:openid,
|
||||
template_id:template_id,
|
||||
url:"https://www.trustie.net/",
|
||||
topcolor:"#FF0000",
|
||||
data:{
|
||||
first: {
|
||||
value:first,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword1:{
|
||||
value:key1,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword2:{
|
||||
value:key2,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword3:{
|
||||
value:key3,
|
||||
color:"#173177"
|
||||
},
|
||||
remark:{
|
||||
value:remark,
|
||||
color:"#173177"
|
||||
}
|
||||
}
|
||||
}
|
||||
data
|
||||
end
|
||||
|
||||
def homework_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
||||
uw = UserWechat.where(user_id: user_id).first
|
||||
unless uw.nil?
|
||||
data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI",first, key1, key2, key3, remark
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
Rails.logger.error "[homework] ===> #{e}"
|
||||
end
|
||||
Rails.logger.info "send over. #{req}"
|
||||
end
|
||||
end
|
||||
|
||||
def topic_publish_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
||||
uw = UserWechat.where(user_id: user_id).first
|
||||
unless uw.nil?
|
||||
data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ",first, key1, key2, key3, remark
|
||||
Rails.logger.info "start send template message: #{data}"
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
Rails.logger.error "[topic_publish] ===> #{e}"
|
||||
end
|
||||
Rails.logger.info "send over. #{req}"
|
||||
end
|
||||
end
|
||||
|
||||
def comment_template(user_id, first, key1, key2, key3, remark="具体内容请点击详情查看网站")
|
||||
uw = UserWechat.where(user_id: user_id).first
|
||||
unless uw.nil?
|
||||
data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",first, key1, key2, key3, remark
|
||||
Rails.logger.info "start send template message: #{data}"
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
Rails.logger.error "[comment] ===> #{e}"
|
||||
end
|
||||
Rails.logger.info "send over. #{req}"
|
||||
end
|
||||
end
|
||||
|
||||
def message_update_template(user_id, first, key1, key2, remark="具体内容请点击详情查看网站")
|
||||
uw = UserWechat.where(user_id: user_id).first
|
||||
unless uw.nil?
|
||||
data = {
|
||||
touser:uw.openid,
|
||||
template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg",
|
||||
url:"https://www.trustie.net/",
|
||||
topcolor:"#FF0000",
|
||||
data:{
|
||||
first: {
|
||||
value:first,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword1:{
|
||||
value:key1,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword2:{
|
||||
value:key2,
|
||||
color:"#173177"
|
||||
},
|
||||
remark:{
|
||||
value:remark,
|
||||
color:"#173177"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rails.logger.info "start send template message: #{data}"
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
Rails.logger.error "[message_update] ===> #{e}"
|
||||
end
|
||||
Rails.logger.info "send over. #{req}"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue